How to show only the 70 first rows with no pagination? And only sort these first 70 rows.

How to show only the 70 first rows with no pagination? And only sort these first 70 rows.

ChromChrom Posts: 44Questions: 15Answers: 1
edited May 2022 in Free community support

Is it possible with client side processing to show only the first 70 rows and no further pagination? And also sort only these first 70 rows when the user clicks on sorting?

At the moment all the rows are loaded get sorted and then shown with pagination. But I only need the first 70 records of this resultset. Or do I need to do server side stuff, which I try to avoid....

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770

    With client side processing Datatables takes into consideration all the rows supplied. You will need to supply on the 70 rows you want displayed. You can do this server side or if using ajax you can use ajax.dataSrc to remove all but the 70 rows provided in the JSON resposne.

    Kevin

  • ChromChrom Posts: 44Questions: 15Answers: 1
    edited May 2022

    Hey :)
    "You can do this server side"

    but then I would need to implement sorting and search functionality manually if i switch it to server side?

    "you can use ajax.dataSrc to remove all but the 70 rows provided in the JSON resposne."

    The json that I get will be unsorted and is then client side sorted by date with moment. Then of this result I only want the first 70 displayed. I guess removing all but 70 rows with ajax.dataSrc, will be before the sorting or is it possible to do it after all rows are sorted by date?

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770

    but then I would need to implement sorting and search functionality manually if i switch it to server side?

    What I meant is you can fetch the 70 rows with your server side script. If using a SQL like DB you can use LIMIT to limit the number of rows fetched from the DB. This does not require enabling server side processing.

    The json that I get will be unsorted and is then client side sorted by date with moment.

    You can use pageLength to set the length to 70 and use paging to turn off paging. If you return more than 70 rows Datatables will perform sorting of all the rows supplied. Again if you have a SQL like DB use ORDER BY to order by the date column along with LIMIT to limit the response to 70 rows.

    I guess removing all but 70 rows with ajax.dataSrc, will be before the sorting or is it possible to do it after all rows are sorted by date?

    Yes the data is in the order supplied by the server.

    Kevin

  • colincolin Posts: 15,146Questions: 1Answers: 2,586
    edited May 2022 Answer ✓

    Another option would be to remove the rows in initComplete - by then the records would be sorted - see example here. This is fine when not much data, but may not be as smooth if many records.

    Colin

  • ChromChrom Posts: 44Questions: 15Answers: 1

    Thanks all of you!!!
    @colin that worked ;-)

Sign In or Register to comment.