How to get data from all rows in paginated datatable?

How to get data from all rows in paginated datatable?

Jerry555555Jerry555555 Posts: 5Questions: 1Answers: 0
edited November 2020 in Free community support

I'm using DataTables V1.5.0 and I am trying to get every unique data from all the rows but it is only returning data from the rows of first page. My implemented code is below.

$('#basicTable').DataTable({
    ...
    initComplete: function () {
        this.api().columns().every(function () {
             let column = this
             column.data().unique().sort().each( function (d) {
                  console.log(d)
              })
          })
      }
})

Please point out what I'm doing wrong and also how to solve the issue. Any help would be appreciated. Thanks

This question has an accepted answers - jump to answer

Answers

  • Jerry555555Jerry555555 Posts: 5Questions: 1Answers: 0

    To be clear: Table is server sided.

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    Yep, with serverSide, only the data on the page is known to the client, so that would be expected. Do you need serverSide? How many records are in your data set?

    Colin

  • Jerry555555Jerry555555 Posts: 5Questions: 1Answers: 0

    Yes. I do need serverSide option. There are only 300 records. Is there any change I can do at client side or even at server side to get all records?

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    With only 300 records you don't need the server side option enabled. This way all 300 records are returned to the client. Try removing or commenting out serverSide: true to see what happens.

    Kevin

  • Jerry555555Jerry555555 Posts: 5Questions: 1Answers: 0

    By commenting out serverSide, I get all the data in the request but table gets stuck on loading and does not display any data. How can I solve this?

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923
    Answer ✓

    I get all the data in the request but table gets stuck on loading and does not display any data. How can I solve this?

    Sounds like you are getting an error. Look at your browser's console.

    Kevin

  • Jerry555555Jerry555555 Posts: 5Questions: 1Answers: 0

    Thank you @kthorngren & @colin . This does solve the problem. This is my first time working with DataTables and I thought I had to change a lot of code to convert from server side to client side. But its fairly simple. Thanks again

This discussion has been closed.