access number of Filters Active

access number of Filters Active

montoyammontoyam Posts: 568Questions: 136Answers: 5

at the top of a SearchPane there is a count of how many filters are selected. I can't find any documentation that shows how we can grab that count. Is it possible?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,177Questions: 1Answers: 2,590
    Answer ✓

    There isn't an API to get it, but you can count the rows with the classes like this:

    $('.dtsp-searchPanes tr.selected').length
    

    Colin

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    That will work, as long as they only select one for each filter, which appears to be what the 'Filters Active' count at the top is doing anyway...I didn't realize that.

    Thanks.

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    I am having trouble with the syntax for detecting when a filter item is clicked. I have tried the 'normal' ones but they don't work

        //$('div.dtsp-searchPanes table tr').on("click", function () {
        $('div.dtsp-searchPanes tbody').on('click', 'td.dtsp-nameColumn', function () {
            console.log($('.dtsp-searchPanes tr.selected').length);
        });
    
  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Try:

    $(document).on('click', ''div.dtsp-searchPanes tbody td.dtsp-nameColumn', ...
    

    Allan

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Out of interest, why do you need to do that? I'm wondering if you might be better using draw on the main table.

    Allan

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    I have a select input and button that is going to do some record updates for the records that are showing. However, I need to make sure they have filtered the records using each of the three searchPane filters so they don't accidently update ALL the records in the dataset. So, I am disabling the button until they have selected 3 filter items.

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Ah - very interesting. I was wondering if we should be triggering an event or making that kind of thing available through an API method. What we might look at doing is making an API method which exposes the DataTables that SearchPanes is using, then you can listen for events on them, etc.

    Allan

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    this didn't seem to work either...

        $(document).on('click', 'div.dtsp-searchPanes tbody td.dtsp-nameColumn', function () {
            console.log($('.dtsp-searchPanes tr.selected').length);
        });
    
  • colincolin Posts: 15,177Questions: 1Answers: 2,590

    This one seems to work, see here:

          $('div.dtsp-searchPanes tbody td.dtsp-nameColumn').on('click', function () {
            console.log($('.dtsp-searchPanes tr.selected').length);
          });
    
  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    thank you. I have decided instead to let the user click the update button, but stop/inform them if they did not have the correct number of filters. This way I don't have to clutter the page with any instructions.

    But, thank you, as I'm sure i will use the .on(click) method in the future and it could benefit others.

    And thank you Allan, for such an awesome product and your dedication to continually adding new functionality to it.

            if ($('.dtsp-searchPanes tr.selected').length < 2) {
                alert('You must select at least two filters above to make this update');
            } else {
                if ($('#newRate').val() == 0) {
                    alert('You must select a new Rate to assign to these records');
                } else {
    
  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Thank you :)

Sign In or Register to comment.