Fetching the current values from an ordered page
Fetching the current values from an ordered page
Greetings Gurus,
I'm having trouble grabbing the cell values from the currently displayed page in an ordered table. In this example the table is sorted on column 3 ("age") and I have an onpage event that's supposed to fetch the values that are currently being displayed in that column. I'm expecting to see return values like "27, 27, 28, 30, 33,....". Instead, I'm getting the values, but they're unordered ("30, 18, 48, 21,..."). I've tried every select-modifier combination, and it doesn't affect the result. Any insight into what I'm doing wrong would be greatly appreciated.
Here's the code:
var table = $('#example').DataTable({
order: [[3, "asc"]],
displayLength: 10
});
$("#example").on("page.dt", function() {
var info = table.page.info();
var age;
for (var i = info.start; i < info.end; i++) {
age = table.cell(i, 3, {order: 'current'}).data();
console.log(age);
}
});
Again, here's a working example:
http://live.datatables.net/zokimele/7/edit
This question has accepted answers - jump to:
Answers
I think the cell row index
i
you are using is the original state of the table before sorting, etc. I updated your example to use the following:There may be other ways to pull the data but this example can be seen here:
http://live.datatables.net/lasamahu/1/edit
Kevin
and
would be other options in addition to Kevin's answer.
Allan
Thanks for your help on this.