rows() and pagination

rows() and pagination

ysayitaysayita Posts: 4Questions: 0Answers: 0

Greetings to all;
I have been trying to utilize Datatables for my MVC application and I have a problem regarding rows() api extension and pagination.
After initialization of the datatable using the var table = $(".blabla").DataTable() function with parameters including "pagination: true", I create some other details for each row using table.rows().every(function () {}); But this only works for the rows on the first page which is currently open. When I debug, table.rows() function returns only the visible rows. Is there a way of getting all rows of the table?

Replies

  • allanallan Posts: 63,810Questions: 1Answers: 10,516 Site admin

    My guess is that you have serverSide enabled, but without a test case (per the forum rules) it is impossible to say for sure.

    If you do have server-side processing enabled, then this is expected, only the rows which are displayed are available at the client-side.

    If you don't, then we'd need a test case to be able to debug it and offer any help.

    Allan

  • ysayitaysayita Posts: 4Questions: 0Answers: 0

    Hi Allan;

    I am not using the serverSide option enabled. Is there a way for me to provide you a debug environment?

    Thanks.

    Yusuf

  • allanallan Posts: 63,810Questions: 1Answers: 10,516 Site admin

    Information on how to create a test page, if you can't provide a link to your own page can be found here.

    Thanks,
    Allan

  • ysayitaysayita Posts: 4Questions: 0Answers: 0

    Hi Allan;

    You may find the test environment set here: https://jsfiddle.net/ysayita/o595dg78/6/

    As you can see there, rows on the first page has details hidden and shows when they are clicked on. But the rows on the other page does not have the same functionality. When you debug, you will see that table.rows() function, returns only the visible 10 rows on the first page.

    Thanks.

  • allanallan Posts: 63,810Questions: 1Answers: 10,516 Site admin

    I added console.log( this.id() ); to the code and it shows that it is calling the loop for every row.

    Your issue is:

    var div = document.getElementById(id);

    That can only select elements that are currently shown. Use row().node() to get the tr element for the row.

    Allan

  • ysayitaysayita Posts: 4Questions: 0Answers: 0

    Allan;

    Thanks to your comment and methodology I could resolve the issue. The working example may be found here:
    https://jsfiddle.net/ysayita/trmc1nbc/1/

This discussion has been closed.