Add SearchPanes filter count to custom button?

Add SearchPanes filter count to custom button?

jwasionjwasion Posts: 4Questions: 1Answers: 0

Hi,

I've added a button to collapse the .searchPanes div without collapsing the whole SearchPanes container (which is why I'm avoiding the default searchPanes button). However, I would like to add the functionality of the active filter count in the button text (e.g. "Advanced Filters (2 Active)" ). Is there a way to use the searchPane button language options on my custom button, or do I need a special function update the button text? I'm not sure how to approach this.

I would also like to remove the default title div from SearchPanes. I'm currently hiding it in css, but if there's a way to eliminate it entirely in the searchPane options, that would be preferable.

http://live.datatables.net/jigixuqe/1/edit

Thanks!

This question has accepted answers - jump to:

Answers

  • sandysandy Posts: 913Questions: 0Answers: 236
    Answer ✓

    Hi @jwasion ,

    Thanks for the example, I like what you are going for and it works really well :)

    Take a look at this example. Here I am making use of a config option called searchPanes.filterChanged(), the SearchPanes button uses this function to update it's text accordingly (see here).

    We hadn't documented this option as we couldn't see why anyone would ever need it, but clearly you do have use for it, so we will be adding to the docs for the next SearchPanes release. We expect this to be within the next couple of weeks. I also made a slight tweak to the SearchPanes code for this, so make sure that you are using the latest nightly build.

    As for removing the title div from SearchPanes, removing it with css or jquery is probably the best route to take here. I'm afraid there isn't a config option to just remove it entirely. You can empty the text using language.searchPanes.title, but that won't remove the div.

    Thanks,
    Sandy

  • jwasionjwasion Posts: 4Questions: 1Answers: 0

    That works great, thank you!

  • jwasionjwasion Posts: 4Questions: 1Answers: 0

    Follow-up question: Is it possible to add a listener using filterChanged for executing functions after the table is created? The main reason I ask is because I'm also using the Responsive extension, and my column widths are having issues when SearchPane filters are selected (headers misalign, and sometimes columns in the body unhide and overflow even when their column headers remain hidden). So I'd like to refresh the columns each time the filter selection changes. What would be the best way to do that?

    Thanks again!

  • sandysandy Posts: 913Questions: 0Answers: 236
    Answer ✓

    Hi @jwasion,

    While I suppose you could approach it that way, I'd recommend using either the draw or the search as listeners to then perform this, as both will be triggered when using SearchPanes to filter rows.

    If you could build a test case or link to your page showing the problem I would be happy to take a closer look. 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.

    Thanks,
    Sandy

  • jwasionjwasion Posts: 4Questions: 1Answers: 0

    Thanks @sandy, I got it working with the search event.

    table.on('search.dt', function () {
        table.responsive.recalc();
    })
    
This discussion has been closed.