how to get the data from different pages

how to get the data from different pages

Jerry2016Jerry2016 Posts: 7Questions: 4Answers: 0

Currently, I can only get the data from the 1st page, through the below js code, how can I get all the data from other pages

$('table > tbody  > tr').each(function (i, el) {
    var selectedVal = $(this).find("option:selected").text();
    var $tds = $(this).find('td');
    var obj = {
        permNo: $tds.eq(0).text(),
        fileType: selectedVal,
        refer: $tds.eq(3).text()
    }
    permlist.push(obj);
})

Answers

  • rf1234rf1234 Posts: 2,990Questions: 87Answers: 421
    edited September 26

    You would need to use the api if you want to be able to get more than what is currently displayed on the screen.

    https://datatables.net/reference/api/rows().data()

  • Jerry2016Jerry2016 Posts: 7Questions: 4Answers: 0

    Thanks, but this is able to get the all the rows, but how can I get the updated column data, for example, I changed the column 2 and 3 in the1st row, but not reflected in the array.

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949
    edited September 26

    I suspect you are running into the issue discussed in this FAQ.

    For your first code snippet you can loop all rhe rows using rows().every(). See the docs for examples. You can also use row().node() in the function to get the row node. Maybe something like this will do what you want:

    table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
        var data = this.data();
        var node = this.node();
        // ... do something with data(), or this.node(), etc
    
        var selectedVal = node.find("option:selected").text();
    
        var obj = {
            permNo: data[0],
            fileType: selectedVal,
            refer: data[3]
        }
        permlist.push(obj);
    
    } );
    

    If you still need help then please post a link to a test case replicating what you are doing so we offer more specific suggestions.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • rf1234rf1234 Posts: 2,990Questions: 87Answers: 421
    edited September 26

    If you change the values outside the api you will not be able to do this. Please learn how to manipulate row data using the api.

    I recommend purchasing an Editor license. Makes it a lot easier.

    But I just see: @kthorngren has an advice for you. :smile:

    Many ways lead to Rome!

Sign In or Register to comment.