Is there a way for length menu to not count hidden rows in the number of rows?

Is there a way for length menu to not count hidden rows in the number of rows?

eris24eris24 Posts: 4Questions: 1Answers: 0
edited November 2021 in DataTables

I need the hidden rows to be included in my table in the background but I don't want the customers getting confused by the "show 10 entries" menu when they see 1 row on there end because I have 9 hidden rows

Answers

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

    When you see hidden rows, do you mean rows that have been filtered out by the search?

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • eris24eris24 Posts: 4Questions: 1Answers: 0

    no, I set the rows to be manually hidden by using a class. I can't filter them out with the search, because I filter them out with the search, the hidden rows won't be exported anymore. I need the hidden row data to be exported.

  • eris24eris24 Posts: 4Questions: 1Answers: 0
    edited November 2021

    for example here http://live.datatables.net/hufojaki/1/edit

    I have the other rows visibility set to "collapse" because I don't want users to see those rows, however, I do still need those row data so that when I export the table to excel or pdf, those data would still be included.

    but the pagination and the length menu is getting messed up because of this.
    What would be a workaround for this so that the length menu would only show/count the rows the users need to see?

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    Datatables assumes the rows are displayed. It doesn't know about rows hidden outside of Datatables API's. One option is to use Datatables search to hide the rows then use the technique in this example to export all the rows. Use the selector-modifier of {search:'none'}.

    Another option is to use infoCallback to customize the info element output. You will need to count the rows that have the CSS visibility:collapse. Use the rows().nodes() API to get the nodes of all the rows, not just the rows on the page displayed. See this example. Note that since Datatables doesn't know about the rows hidden this way your paging won't be correct. You can see it in your test case. You can use api pege.len() to dynamically set the page length but there is not an option to dynamically set the =option lengthMenu. You could create your own page length menu.

    Kevin

  • eris24eris24 Posts: 4Questions: 1Answers: 0

    Would you be able to give a rough draft of that code in the example please?

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    The code to handle paging when using visibility:collapse would take some work as you are replacing / augmenting features of Datatables. Preparing an example for this is beyond the scope of this forum. However if you want to update your example and ask Datatable specific questions we are glad to help.

    My suggestion is to add a hidden column, use column.visible with a keyword you can search for to filter the rows you don't want to display and use the selector-modifier I suggested to export all the rows.

    Kevin

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    You can use the search option to define the initial search.

    Kevin

Sign In or Register to comment.