forked from ephemer/meteor-reactive-datatables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreactive-datatables.js
32 lines (29 loc) · 934 Bytes
/
reactive-datatables.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
ReactiveDatatable = function(options) {
var self = this;
this.options = options = _.defaults(options, {
// Any of these can be overriden by passing an options
// object into your ReactiveDatatable template (see readme)
stateSave: true,
stateDuration: -1, // Store data for session only
pageLength: 5,
lengthMenu: [3, 5, 10, 50, 100],
columnDefs: [{ // Global default blank value to avoid popup on missing data
targets: '_all',
defaultContent: '–––'
}],
stateLoadParams: function(settings, data) {
// Make it easy to change to the stored page on .update()
self.page = data.start / data.length;
}
});
};
ReactiveDatatable.prototype.update = function(data) {
if (!data) return;
var self = this;
self.datatable
.clear()
.rows.add(data)
.draw(false)
.page(self.page || 0) // XXX: Can we avoid drawing twice?
.draw(false); // I couldn't get the page drawing to work otherwise
};