Reload data of datatable
Reload data of datatable
Hi, I'm new and I would like to refresh the contents of my table through javascript
This is part of html code
<table id="carsTable" class="table table-bordered table-striped">
and in javascript I'm using
var table = $('#carsTable').dataTable();
table.api().ajax.reload();
but I receive one popup error
http://postimg.org/image/6e7vows1x/
and into my browser developer tools I can read
Uncaught TypeError: Cannot set property 'data' of null
Someone know where is the error?Thanks
This question has an accepted answers - jump to answer
Answers
I would have said the error was fairly clear - the data returned from the server is not valid JSON. The question is, if it isn't valid JSON, what is it? The link that the error message gives will show you how to find out.
Allan
yes, I have tried but there wasn't no network request to analyze
There wasn't no network request? Then are you sure it's even an AJAX sourced table?..
Can you either show us the page where we can replicate the error, or replicate it in a JSBin instance please?
If you got the invalid JSON error then there was an Ajax request made. That is the only way that error can occur.
Can you run the debugger on your page or give us a link to that page or a test case showing the issue.
Allan
sure, but on Thursday because I won't have notebook until then
No problem - just post back when you have the information needed :-)
Allan
Hi, this is three screen of the error.
http://postimg.org/image/v059l9mz9/
http://postimg.org/image/a4iza0qs5/
http://postimg.org/image/d8tn6t7kl/
Those are just the console logs and the header responses.. how about the actual response content? As in the json? Or the debugger that allan requested? The above doesnt actually help really
sorry, I run the debug on my page and the debug code is: ovaqefv or this is the link with information http://debug.datatables.net/ovaqef
The debug trace shows that no Ajax request was made and no initialisation options were given to DataTables (i.e. there is not
ajax
option).Allan
maybe the problem is that I'm using thymeleaf to fill value into table?
<tr th:each="car : ${carsList}">
<td th:text="${car.id}"></td>
<td th:text="${car.initialKm}"></td>
<td th:text="${car.carChassis}"></td>
<td th:text="${car.carType.idCarType}"></td>
<td th:text="${car.note}"></td>
</tr>
is not possible to update it with this strategy?Because I have table with String or for example buttons
Correct - because DataTables knows nothing about your Ajax, the
ajax.reload()
method can't reload the Ajax data.Allan
thanks, I resolved with this workaround:
$('#fleetsTable').load(document.URL + ' #fleetsTable');
this instruction reload only only the table in the html page