Fixed Row Count

Fixed Row Count

cnj005cnj005 Posts: 1Questions: 1Answers: 0

I'm using datatables with server side processing and I'm trying to figure out how to get datatables to always show a set number of rows. I don't want it to resize vertically when there are less records to display than the set pageLength. If there are only 6 rows to display but the pagelength is 10 then there should be 4 empty rows. If i'm on the last page and there's 2 odd records then there should be 8 empty rows.

I've tried at the server end to add empty rows so it would always return a multiple of 10 (my pagelength) but this creates an issue with sorting and sizing which i may continue to work through but there must be a simple api i can manipulate to set this.

I also found an outdated post (https://datatables.net/forums/discussion/5970/fixed-row-count) on the forum describing how to do this but it looks like the example was cut half way through. There's also mention of an older post giving this information but i can't find it.

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    The way to do this is to use drawCallback or draw (basically the same thing, called in different ways) to inject additional rows into the table after the table has been drawn. That way you don't need to modify the server-side code at all.

    So basically in the draw callback you would check how many rows are in the tbody. If there are less than you want, create them and append them.

    I had thought there was a plug-in for that already, but I don't see it now...

    Allan

This discussion has been closed.