table.rows().data() does not obtain the rows content after migration to ajax source
table.rows().data() does not obtain the rows content after migration to ajax source
Hello,
I have noticed, that after I migrated my table to ajax-sourced (like below)
var url = "ajax-link";
var dt = table.DataTable({
ajax:{
url: apiUrl,
},
columns: [
{data: 'Id'},
{data: 'name'},
.....
});
the table works fine, but I can't obtain the data for further actions in next steps through:
var data = dt.rows().data();
values of rows like - data[0] seem always be "undefined"
So my humble question, is the different way to obtain a table data in ajax-sourced tables?
Thank you in advance for suggestions!
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
My guess is you are using
var data = dt.rows().data();directly after the Datatables initialization code. Since Ajax is an asynchronous operation you need to wait until the response is received and Datatables has finished initializing. Try usinginitComplete. Instead of using thedtvariable you will need to usethis.api()so it will look something like this:Likely you will want to put the further actions in
initComplete.However I'm not sure how/when you are using
var data = dt.rows().data();. If the above doesn't help then please post a link to your page or a test case replicating the issue so we can help debug.https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Thank you for the help! It goes exactly the way you advised! My Datatable works perfectly now!