EloquentStudio / filter.js

Complete solution for client side filtering and rendering using JSON data
http://eloquentstudio.github.io/filter.js
MIT License
665 stars 183 forks source link

Clearing and hiding check boxes #171

Open ready4data opened 5 years ago

ready4data commented 5 years ago

I modified the code for the check boxes to hide the ones with (0) items after filtering.


      var c = $(this), count = 0
      if(result.length > 0){
        count = jQ.where({ 'litType': c.val() }).count;
      }
      //hide the checkboxes if value is 0////////
      if (count ==0) { 
          $('#'+c.val().replace(/\s/g, '')).hide();
      } else {
          $('#'+c.val().replace(/\s/g, '')).show();
      }   
      c.next().text(c.val() + '(' + count + ')')
    });```

I'm trying to figure out how to uncheck All and the items that are left so 
the user can just pick the item they want. Currently they have to first 
uncheck All, then check the item they actually want.
PeterPan73 commented 5 years ago

Hi @ready4data did you find any solution? And I'm interested in that.

ready4data commented 5 years ago

I did do this which works but produces some unexpected filtering. I have two different sections with checkboxes Literature Type and Product Type After entering your search terms, the page refreshes and the checkboxes are all unchecked. If I check off an item it either area, it works. If I select an item in one area and then the other, it gives unexpected results in the search.

function afterFiltered(){//Unchecks the boxes after a search
  $('#litType_criteria :checkbox').prop('checked', false);
 /$('#prodType_criteria :checkbox').prop('checked', false);  
}

And added that function to the callback.

PeterPan73 commented 5 years ago

Thanks for the answer. But if all are unchecked by default, when you checked one of the checkbox, the counter of the others is reset(will be 0). Did you find any solution to this?