Reload data of datatable

Reload data of datatable

lucacali87lucacali87 Posts: 30Questions: 10Answers: 2

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

  • allanallan Posts: 63,760Questions: 1Answers: 10,510 Site admin

    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

  • lucacali87lucacali87 Posts: 30Questions: 10Answers: 2

    yes, I have tried but there wasn't no network request to analyze

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    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?

  • allanallan Posts: 63,760Questions: 1Answers: 10,510 Site admin

    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

  • lucacali87lucacali87 Posts: 30Questions: 10Answers: 2

    sure, but on Thursday because I won't have notebook until then

  • allanallan Posts: 63,760Questions: 1Answers: 10,510 Site admin

    No problem - just post back when you have the information needed :-)

    Allan

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    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

  • lucacali87lucacali87 Posts: 30Questions: 10Answers: 2

    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

  • allanallan Posts: 63,760Questions: 1Answers: 10,510 Site admin

    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

  • lucacali87lucacali87 Posts: 30Questions: 10Answers: 2
    edited October 2015

    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

  • allanallan Posts: 63,760Questions: 1Answers: 10,510 Site admin

    Correct - because DataTables knows nothing about your Ajax, the ajax.reload() method can't reload the Ajax data.

    Allan

  • lucacali87lucacali87 Posts: 30Questions: 10Answers: 2
    Answer ✓

    thanks, I resolved with this workaround:
    $('#fleetsTable').load(document.URL + ' #fleetsTable');
    this instruction reload only only the table in the html page

This discussion has been closed.