DataTable dynamic lengthMenu array

DataTable dynamic lengthMenu array

cindyparellcindyparell Posts: 5Questions: 2Answers: 1

We recently started using DataTable and it is a great plugin. There are lot of rows in the table and hence I am using paging. But rows per page seems to be static. How can we build a dynamic array for lengthMenu option based on the total number of rows that the datatable is built off of?

Answers

  • allanallan Posts: 63,175Questions: 1Answers: 10,409 Site admin

    How can we build a dynamic array for lengthMenu option based on the total number of rows that the datatable is built off of?

    Could you give me an example of that? If the table has 50 or 500 records, would you want to change the options in the list?

    Allan

  • cindyparellcindyparell Posts: 5Questions: 2Answers: 1

    Yes. My table has more than 2000 rows and it varies depending on business users are viewing. So i want to calculate the number of pages available for the result set of the table.

  • allanallan Posts: 63,175Questions: 1Answers: 10,409 Site admin

    DataTables will do that for you. The language.info option has options to show the number of pages and the current page.

    I'm still not getting the dynamic length menu though I'm afraid. Are you saying you want different options if your table has 100 records than if it has 2000 records?

    Allan

  • cindyparellcindyparell Posts: 5Questions: 2Answers: 1

    I am sorry for not being clear. I think the lengthMenu array is static. If a business has 100 rows, then it makes sense to show 25 rows per page, 50, 75, ALL and not show beyond 100 in the lengthMenu for its values(dynamically build this array). On the other hand, if another business has 500 rows to display in the same datatable, then the lengthmenu should show 25 rows per page, 50, 75, 100, 125, 150 etc to 500 in the increments of 25. This behavior should be dynamic based on number of rows returned to datatable. Hope this helps understand my issue.

  • allanallan Posts: 63,175Questions: 1Answers: 10,409 Site admin

    Yes - I'm with you now. Thanks for the clarification. There isn't a DataTables API for that as such, but you could readily manipulate the select using the DOM - e.g.: http://live.datatables.net/puropove/1/edit .

    Allan

This discussion has been closed.