Is there a way to un-search a table?

Is there a way to un-search a table?

WhetDawgWhetDawg Posts: 5Questions: 2Answers: 0

I need to filter the table based on attributes on the TR element. I have that working but now realize the user is unable to filter by other values because it's subtracting the rows.

1

How do I restore the original records?

https://jsfiddle.net/WhetDawg/gopchs6d/31/

2

Is there a better way to filter by attributes?

Thanks.

This question has an accepted answers - jump to answer

Answers

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

    If the chosen select list option is empty then return true in the search plugin, like this:
    https://jsfiddle.net/8u0hobyk/

    Kevin

  • WhetDawgWhetDawg Posts: 5Questions: 2Answers: 0

    Thanks! I'd like to be able to choose any value in the dropdown and get the results.

    I choose "Indoor" it filters for the 2 Indoor Products.
    If I then chose "Outdoor", it shows no products.
    However, If I choose "Indoor", then "" (empty) and then "Outdoor", it shows the 2 Outdoor products.

    I can add:
    $.fn.dataTable.ext.search.push(
    function (settings, data, dataIndex) { return true; });
    tbl.draw();
    $.fn.dataTable.ext.search.pop();

    before I do my actual filtering and that works. I'm not seeing any screen flicker as it shows all 6 records and then filters for only 2 each time.

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,771
    Answer ✓

    Pushing then popping in the event handler isn't going to work properly. Once you pop the plugin then perform another draw, like searching, sorting or paging, the filters applied by the plugin will be removed. You can see this by selecting Indoor for example the in the search input try searching for something. Clear the search input and you will see all the rows.

    Just enable the plugin by pushing it then get the input value and if empty return true. Use row().node() to get the row's node then the jQuery data() API to get the product-id from the row. Compare that to the input value.

    aProduct_Ids = $('tbody tr', $tbl).map(function (index, ele)

    Datatables will only have the rows displayed on the page in the DOM. This won't find all the rows if any are filtered or on another page. Likely why its not working as expected.

    Here is the updated example:
    https://jsfiddle.net/7dwzmfn2/

    Kevin

  • WhetDawgWhetDawg Posts: 5Questions: 2Answers: 0

    Thank you for the awesome solution! Even RowGrouping now works correctly. :)

Sign In or Register to comment.