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
+50-26Lines changed: 50 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,23 +17,39 @@ Basic requirement to implement filtering using filter.js are JSON data, View tem
17
17
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
18
Others are in options like criteria, callbacks, search.
19
19
20
-
```
20
+
```javascript
21
21
varFJS=FilterJS(movies, '#movies', {
22
22
template:'#movie-template',
23
-
callbacks: {
23
+
callbacks: {
24
24
afterFilter:function(result){
25
25
$('#total_movies').text(result.length);
26
26
}
27
27
}
28
28
});
29
29
```
30
30
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.
33
+
34
+
```javascript
35
+
36
+
//This will append elements to specific year.
37
+
varappendFn=function(html_ele, record){
38
+
$("#"+record.year).append(html_ele);
39
+
}
40
+
41
+
varFJS=FilterJS(movies, '#movies', {
42
+
template:'#movie-template',
43
+
appendToContainer: appendFn
44
+
});
45
+
```
46
+
31
47
### JSON data
32
48
-------------
33
49
34
50
Capture the JSON data (maybe using @movies.to_json). i.e
35
51
36
-
```
52
+
```javascript
37
53
var movies = [
38
54
{
39
55
"name":"The Shawshank Redemption",
@@ -63,7 +79,7 @@ Capture the JSON data (maybe using @movies.to_json). i.e
63
79
To render each json object require view template. In filter.js micro-templating module inspired by Underscopre.js.
64
80
65
81
66
-
```
82
+
```javascript
67
83
<script id="movie-template" type="text/html">
68
84
<div class="movie">
69
85
<div class="thumbnail">
@@ -104,21 +120,21 @@ Other options are filter `type`, `event` and `selector`.
104
120
105
121
There are two way to add criteria one is add at time of filter object initialisation and other one is add when required
For nested field selection. In below object to select filter on name `field` option value would be `detail.name`, for city `detail.address.city`.
137
153
138
154
Json object:
139
155
156
+
```json
157
+
140
158
{
141
159
detail: { name:'Jiren', address: {city:'Pune'} }
142
160
}
161
+
```
143
162
144
163
#### Remove criteria.
145
164
146
165
Using `removeCriteria`, remove criteria dynamically. It take one argument `filed` name. i.e removing year criteria.
147
166
148
-
```
167
+
```javascript
149
168
fjs.removeCriteria('year')
150
169
```
151
170
@@ -162,7 +181,8 @@ Define callback in settings. Callbacks execute on different events.
162
181
163
182
i.e
164
183
165
-
```
184
+
```javascript
185
+
166
186
var filter_callbacks = {
167
187
beforeAddRecords:function(records){
168
188
// Process new json data records.
@@ -185,7 +205,8 @@ i.e
185
205
186
206
Init Filter object with above callbacks
187
207
188
-
```
208
+
```javascript
209
+
189
210
var fjs =FilterJS(movies, '#movies', {
190
211
template:'#movie-template',
191
212
callbacks: filter_callbacks
@@ -203,28 +224,30 @@ var fjs = FilterJS(movies, '#movies', {
203
224
204
225
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.
205
226
206
-
```
207
-
# Init with search
227
+
```javascript
228
+
229
+
// Init with search
208
230
FilterJS(movies, '#movies', {
209
231
template:'#movie-template',
210
232
search: {ele:'#searchbox'} // Search in all fields of json object.
0 commit comments