How do I redraw or destroy a datatable I declare in my xhtml. I tried everything but it simply doesnt work.
This is my 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>
And this is how I am trying to access it in my script:
<script>
function change() {
event.preventDefault();
$('#f:\\book').DataTable().clear();
$('#f:\\book').DataTable().destroy();
}
</script>
These are my imports:
<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>
I even tried accessing the table like this $("$book)
and calling html
or append
to it. But nothing works. I don't even get any errors.
Any suggestions/recommendations?