You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+32-58Lines changed: 32 additions & 58 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,15 @@
1
-
Filter.js
2
-
=============
1
+
# Filter.js
3
2
4
3
Filter.js is client-side JSON objects filter and render html elements.
5
4
Multiple filter criteria can be specified and used in conjunction with
6
5
each other.
7
6
8
-
9
-
Usage
10
-
-----
7
+
## Usage
8
+
***
11
9
12
10
Basic requirement to implement filtering using filter.js are JSON data, View template and filter criteria.
13
11
14
12
### Filter Initialisation
15
-
-------------------------
16
13
17
14
It takes three arguments one is movies, second is container in which html element going to append, third one is options. Options must have template element selector.
18
15
Others are in options like criteria, callbacks, search.
@@ -28,8 +25,7 @@ var FJS = FilterJS(movies, '#movies', {
28
25
});
29
26
```
30
27
31
-
To append in each item in different container use option `appendToContainer`. This option is a function with two arguments
32
-
one is html element content and second is record object.
28
+
To append in each item in different container use option `appendToContainer`. This option is a function with two arguments, one is html element content and second is record object.
33
29
34
30
```javascript
35
31
@@ -45,7 +41,6 @@ var FJS = FilterJS(movies, '#movies', {
45
41
```
46
42
47
43
### JSON data
48
-
-------------
49
44
50
45
Capture the JSON data (maybe using @movies.to_json). i.e
51
46
@@ -74,10 +69,8 @@ Capture the JSON data (maybe using @movies.to_json). i.e
74
69
```
75
70
76
71
### View
77
-
--------
78
-
79
-
To render each json object require view template. In filter.js micro-templating module inspired by Underscopre.js.
80
72
73
+
To render each json object require view template. In filter.js micro-templating module inspired by Underscore.js.
81
74
82
75
```javascript
83
76
<script id="movie-template" type="text/html">
@@ -108,10 +101,10 @@ To render each json object require view template. In filter.js micro-templating
108
101
```
109
102
110
103
### Filter Criteria
111
-
-------------------
112
104
113
105
It required two mandatory options are `field` which is name of any property from json data and other is HTML `ele` element on which filter will be trigger by click,change etc events.
114
106
Other options are filter `type`, `event` and `selector`.
107
+
115
108
- filter `type`, by default it is equal but if you want to search in range you can set it `range`. For `range` html element value should be in format of `val1-val2`. i.e `100-200`.
116
109
-`delimiter`, by default hyphen '-' is used as range seperator `val1-val2`. If you want to use a different seperator (if data contains hyphen e.g: ' 2012-02-02 ') it can be specified using `delimiter: ','` and html element value should be in format `val1<delimiter>val2`. i.e.`2012-02-02,2015-02-02`.
117
110
-`event` by default for checkbox, radio button is `click`, for text input, select box is `change`.
@@ -139,7 +132,8 @@ There are two way to add criteria one is add at time of filter object initialisa
139
132
```
140
133
141
134
**field**: `genre` this is a JSON attribute defined in JSON objects.
142
-
For Range selections,
135
+
136
+
#### For Range selections
143
137
144
138
More detail for `range` filter. It is expected to set ranges as values like '20-30'
145
139
@@ -168,8 +162,7 @@ Using `removeCriteria`, remove criteria dynamically. It take one argument `filed
168
162
fjs.removeCriteria('year')
169
163
```
170
164
171
-
### Filtering Callbacks
172
-
-------------------
165
+
#### Filtering Callbacks
173
166
174
167
Define callback in settings. Callbacks execute on different events.
175
168
@@ -179,7 +172,7 @@ Define callback in settings. Callbacks execute on different events.
179
172
- `beforeRecordRender` : Trigger for each json object record at time of rendering.
180
173
- `afterFilter` : Trigger after filtering event.
181
174
182
-
i.e
175
+
i.e.,
183
176
184
177
```javascript
185
178
@@ -203,7 +196,7 @@ i.e
203
196
};
204
197
```
205
198
206
-
Init Filter object with above callbacks
199
+
#### Init Filter object with above callbacks
207
200
208
201
```javascript
209
202
@@ -218,9 +211,7 @@ var fjs = FilterJS(movies, '#movies', {
218
211
});
219
212
```
220
213
221
-
222
214
### Instant Search integration
223
-
---------------------------
224
215
225
216
For search needed textbox element selector. By default search will work on all json object fields. If needed search in particular fields then set `fields` option.
226
217
@@ -251,10 +242,8 @@ Default search will start searching immediately after user types. A timeout can
0 commit comments