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

Any or all #26

Closed jamiepittock closed 10 years ago

jamiepittock commented 10 years ago

I'm using a select field as a filter

<select id="type_filter">
    <option value="">Any type</option>
    <option value="5">Bush Walk</option>
    <option value="6">Cycle</option>
    <option value="11">Drive (2WD)</option>
    <option value="51">Drive (4WD)</option>
</select>

I can't work out how I'd basically reset the filter if you select the "Any type" option.

Could you point me in the right direction?

jamiepittock commented 10 years ago

Similarly, I'm also struggling to filter a single checkbox.

I want to use a criteria like this:

toptrail: ['#toptrails_filter:checkbox', 'is_toptrail']

This would be a checkbox looking like this:

<input type="checkbox" id="toptrails_filter" value="y">

Clicking the checkbox filters the results to only show the items with JSON attribute is_toptrail with a value of 'y' but unchecking it again hides all the items rather than showing them all again.

I'm not sure whether it's me just not understanding or I'm missing something obvious?

jiren commented 10 years ago

First point select box: There is two to do it.

  1. define custom filter like
    var selectFilter = function(category_value, type){
      if(category_value == ''){
        return true;
      }else{
        return  category_value == type
      }
    };

  //in setting options
  type:    ['#type_filter .TYPE.select', 'type'],
  1. We can add functionality in filter.js options like "all" value
 type:    ['#type_filter .TYPE.select', 'type', {'all': ''}]   

From second point I understood that you want 'OR' filter means if no one is selected show all elements for this you have to set in settings or remove this option, by default it is or filter.

and_filter_on: false

If you trying to do something else please tell.

jamiepittock commented 10 years ago

Thanks very much for the fast response.

I defined a custom filter which worked nicely.

Also changing the and_filter_on setting worked for the other issue.

Many thanks.