forked from ephemer/meteor-reactive-datatables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reactive-datatable-template.js
29 lines (23 loc) · 1.08 KB
/
reactive-datatable-template.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
Template.ReactiveDatatable.rendered = function() {
var data = this.data;
if (typeof data.tableData !== "function") {
throw new Meteor.Error('Your tableData must be a function that returns an array via Cursor.fetch(), .map() or another (hopefully reactive) means')
}
var reactiveDataTable = new ReactiveDatatable(data.options);
// Help Blaze cleanly remove entire datatable when changing template / route by
// wrapping table in existing element (#datatable_wrap) defined in the template.
var table = document.createElement('table');
var tableClasses = data.options.tableClasses || "";
table.className = 'table dataTable ' + tableClasses;
// Render the table element and turn it into a DataTable
this.$('.datatable_wrapper').append(table);
var dt = $(table).DataTable(data.options);
reactiveDataTable.datatable = dt;
dt.on('page.dt', function(e, settings) {
var info = dt.page.info();
reactiveDataTable.page = info.page;
});
this.autorun(function() {
reactiveDataTable.update(data.tableData());
});
};