DataTables: Plugin or Example for Searchable Hidden Rows and Expand All Button?

DataTables: Plugin or Example for Searchable Hidden Rows and Expand All Button?

Noodles12Noodles12 Posts: 115Questions: 42Answers: 2

I'm interested in using the row expansion feature in DataTables (as shown in this example). However, I've encountered a few limitations:

1) Search doesn't include data in collapsed rows — so hidden content isn't searchable. If there is a way to search data in collapsed rows, can the row expand automictically for search results.

2) No built-in "Expand All / Collapse All" toggle — which would be useful for users who want to view all row details at once.

Are there any DataTables plugins or examples that solve these issues?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,922Questions: 26Answers: 5,067
    Answer ✓

    Search doesn't include data in collapsed rows

    The example has this data for all the rows.

        {
          "id": "1",
          "name": "Tiger Nixon",
          "position": "System Architect",
          "salary": "$320,800",
          "start_date": "2011-04-25",
          "office": "Edinburgh",
          "extn": "5421"
        },
    

    The child row shows the name and extn objects. To search extn, for example, define it in a hidden column like this:

        columns: [
            {
                className: 'dt-control',
                orderable: false,
                data: null,
                defaultContent: ''
            },
            { data: 'name' },
            { data: 'position' },
            { data: 'office' },
            { data: 'salary' },
            { data: 'extn', visible: false }
        ],
    

    No built-in "Expand All / Collapse All" toggle

    See the second example from this thread.. You can update the code to make the button a toggle button and show/hide the child rows based on the state of the button.

    can the row expand automictically for search results.

    Use the same code in the search event. Use page.info() to determine if there are filtered records. If there are then show the child rows, if not then hide them.

    I would make a function to show/hide the rows with a parameter to determine which to do. Call that function in the above events with the appropriate parameter.

    Kevin

  • Noodles12Noodles12 Posts: 115Questions: 42Answers: 2

    Thankyou!

Sign In or Register to comment.