reset filtered table

reset filtered table

54696d2054696d20 Posts: 75Questions: 18Answers: 0

Here is my example. Click on filter and select something you want to filter. The table filters out what you want to see. If you hit the reset button. It doesn't do anything. Any ideas

http://live.datatables.net/tobabovo/39/

This question has an accepted answers - jump to answer

Answers

  • sandysandy Posts: 913Questions: 0Answers: 236

    Hi,

    It seems to work fine for me!

    Just incase this is useful for you, we are currently working on SearchPanes and it is getting very close to an official release. Here are some links to an example, and a link to the feedback post for more info.

    Hope this helps,

    Sandy

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

    There are a couple issues I see with your code. If I select a grade, click filter, then click reset it works. Thats because the grade filter is using column(4).search(). This won't clear the select2 search plugin.

    You need to rearrange your search plugins. Each time FilterEOCTable is executed, for example and programChecked contains array values you are pushing a new copy of the plugin onto the search stack. They should only be pushed one and I would do so at the beginning of your script, like this example:
    http://live.datatables.net/yisaqore/1/edit

    Inside the plugin you can check for the length of programChecked and simply return true if empty or run through your code as normal.

    If you want the programChecked to be cleared when clicking the reset button then clear the select2 options and when draw is executed the empty check you move into the plugin will return true for all the rows.

    As Sandy mentioned the Search Panes plugin might be work checking out.

    Kevin

  • 54696d2054696d20 Posts: 75Questions: 18Answers: 0

    @sandy I'm not seeing that its resetting the table. If I filter out a program (TB for example) I'm looking at 2 rows. If I click on reset. The table isn't showing the original rows.

    @kthorngren Yes, if I filter just by the grade, it works. If I filter out by program it filters, but doesn't reset. I haven't put in the logic to reset the select2 select, but the table isn't resetting. Also, I'm not sure what you sent me

    Thanks for the help

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

    As Kevin said:

    Each time FilterEOCTable is executed, for example and programChecked contains array values you are pushing a new copy of the plugin onto the search stack.

    This can be demonstrated by pop()ing one off and doing a draw. Kevin's suggestions are the way to go.

  • 54696d2054696d20 Posts: 75Questions: 18Answers: 0

    I guess I'm not understanding. Reset button calls a different method. So I can't just reset and show all the data again in the table?

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

    I didn't change all of your code, just enough to hopefully get you going.
    http://live.datatables.net/fihubuzi/1/edit

    The first thing that happens is the select2 element is populated. Next the Program search plugin is pushed onto the search stack. I moved the code to check for values in the select2 inside the plugin and placed a default return true at the end if the select2 is empty.

    In the resetFilter event handler I added the following, note it needs to run before you call draw():

      $('.programFilter').val("");  // Make sure to do this before draw()
      $('.programFilter').trigger('change');  // Notify any JS components that the value changed 
    

    So now you can filter on program TA, etc then click reset to have it clear those filters. You will need to do the same with your failedChecked plugin. Also note you only need to call draw once for the plugins to run.

    Kevin

  • 54696d2054696d20 Posts: 75Questions: 18Answers: 0

    @kthorngren :( It took you moving that $.fn.dataTable.ext.search.push outside for it to click. I was thinking that it needed to be called each time. Now everyone's comments make since. Thanks again!

This discussion has been closed.