如何重繪或銷燬我在xhtml中聲明的數據表。我嘗試了一切,但它不起作用。在JSF中操作JQuery中的DataTable
這是我的數據表:
<h:dataTable id= "book" var="book" value="#{bean.booksByAuthor}" rowClasses="even-row,odd-row">
<h:column>
<f:facet name="header">Title</f:facet>
<h:outputText value="#{book.title}" class=""/>
</h:column>
<h:column>
<f:facet name="header">ISBN</f:facet>
<h:outputText value="#{book.ISBN}"/>
</h:column>
<h:column>
<f:facet name="header">Price</f:facet>
<h:outputText value="#{book.price}"/>
</h:column>
<h:column>
<h:commandButton value="Buy" action="buyItem">
<f:param name="book2Buy" value="#{book.ISBN}" />
</h:commandButton>
</h:column>
</h:dataTable>
而且這是我正在試圖訪問它在我的腳本:
<script>
function change() {
event.preventDefault();
$('#f:\\book').DataTable().clear();
$('#f:\\book').DataTable().destroy();
}
</script>
這是我進口:
<script type="text/javascript" src="scripts/jquery-3.2.1.js"></script>
<script type="text/javascript" src="scripts/jquery-ui-1.12.1/jquery-ui.js"></script>
<!-- Data Table-->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jq-2.2.4/dt-1.10.15/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jq-2.2.4/dt-1.10.15/datatables.min.js"></script>
我甚至嘗試訪問此表,如$("$book)
,並致電html
或append
它。但沒有任何工作。我甚至沒有任何錯誤。
任何建議/建議?
首先閱讀[如何使用jQuery選擇JSF組件?](http://stackoverflow.com/questions/7927716/how-to-select-jsf-components-using-jquery) –