Customized search applicable to both normal datatable and datatable with child rows.

Customized search applicable to both normal datatable and datatable with child rows.

AtishAtish Posts: 6Questions: 2Answers: 0
edited January 2018 in Free community support

I have an application with two datatables.

1.Has only parent rows (no child rows) say datatable1.
2.Has parent rows as well as child rows say datatable2.

I want to implement only one search for both the datatables.

For the datatable2 I implemented davidkonrad's answer on this link: https://stackoverflow.com/questions/30471089/datatables-search-child-row-content/ which works fine.
But the search does not work for the datatable2.

Any help would be greatly appreciated.

Thank you.

Answers

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,769
    edited January 2018

    Clever approach!

    You could do something like this:

        $('.dataTables_filter input')
           .off()
           .on('keyup', function() {
              filterByDetailsExtNoAndInput(this.value);
              table2.search(this.value).draw();
           });    
    

    Assuming your second (non child) table is assigned to the variable table2.

    Kevin

  • AtishAtish Posts: 6Questions: 2Answers: 0

    table2.search(this.value).draw(); was giving me a error but table2.fnFilter(this.value); worked for me.

    Thanks for the help.

  • karanlkaranl Posts: 6Questions: 3Answers: 0

    How can I search in two tables so that for 1st table I want datatables default search functionality and for second I want my custom search?
    In my project when I implemented custom search,even when I enter some text in 1st table's search field it was searching in second table.I think this is because of '.dataTables_filter input' class which is same for both search fields of both tables.
    Thank you.

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

    You can use a selector like this for a specific table: $('#myTable_filter input').

    Kevin

This discussion has been closed.