This repository was archived by the owner on Sep 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathexample.js
97 lines (85 loc) · 2.8 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
$(document).ready(function() {
// Collection
var Territories = Backbone.PageableCollection.extend({
state: {pageSize: 15},
mode: "client"
});
var columns = [{name: "id", label: "ID", cell: "integer", editable:false},
{name: "name", label: "Name", cell: "string", editable:false},
{name: "code", label: "Code", cell: "string", editable:false},
{name: "continent_code", label: "Continent", cell: "string", editable:false}];
// ** Example 1 **
(function(){
var territories = new Territories(_.map(_territories, _.clone));
// Grid
var grid = new Backgrid.Grid({
columns: columns,
collection: territories,
className: "backgrid table"
}),
$grid = grid.render().$el;
$("#result").append($grid);
// Paginator
var paginator = new Backgrid.Extension.Paginator({
collection: territories
}),
$paginator = paginator.render().$el;
$("#result").append($paginator);
// Select filter
var filter = new Backgrid.Extension.SelectFilter({
className: "backgrid-filter form-control",
collection: territories,
fields: [{
name:"continent_code",
selectOptions: _.union([{label: "All", value: null}],
_.map(_continents, function(o) {return {label: o.name, value: o.code};}))
}],
}),
$filter = filter.render().$el;
$("#filter").replaceWith($filter);
}).call(this);
// ** Example 2 **
(function(){
var territories = new Territories(_.map(_territories, _.clone));
// Grid
var grid = new Backgrid.Grid({
columns: columns,
collection: territories,
className: "backgrid table"
}),
$grid = grid.render().$el;
$("#result-2").append($grid);
// Paginator
var paginator = new Backgrid.Extension.Paginator({
collection: territories
}),
$paginator = paginator.render().$el;
$("#result-2").append($paginator);
// Select filter
var filter = new Backgrid.Extension.SelectFilter({
className: "backgrid-filter form-control",
collection: territories,
fields:[{
name: "continent_code",
selectOptions: [{
label: "All", value: null
}, {
label: "Americas", value: ["NA", "SA"]
}, {
label: "Europe", value: ["EU"]
}, {
label: "Asia", value: ["AS"]
}, {
label: "Other", value: ["AF", "OC", "AN"]
}]
}],
makeMatcher: function(value) {
return function(model) {
return _.indexOf(value, model.get(this.field)) >= 0;
}
}
}),
$filter = filter.render().$el;
$("#filter-2").replaceWith($filter);
}).call(this);
});