Fetching the current values from an ordered page

Fetching the current values from an ordered page

beeker3000beeker3000 Posts: 2Questions: 1Answers: 0
edited October 2017 in Free community support

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

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    Answer ✓

    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:

        table.rows({order: 'current', page: 'current'}).every( function ( rowIdx, tableLoop, rowLoop ) {
        age = this.data()[3];
        console.log(age);
    

    There may be other ways to pull the data but this example can be seen here:
    http://live.datatables.net/lasamahu/1/edit

    Kevin

  • allanallan Posts: 63,468Questions: 1Answers: 10,466 Site admin
    Answer ✓
    table.rows({order: 'current', page: 'current'}).data().pluck(3);
    

    and

    table.cells( null, 3, {order: 'current', page: 'current'}) ).data()
    

    would be other options in addition to Kevin's answer.

    Allan

  • beeker3000beeker3000 Posts: 2Questions: 1Answers: 0

    Thanks for your help on this.

This discussion has been closed.