-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (31 loc) · 918 Bytes
/
index.js
File metadata and controls
34 lines (31 loc) · 918 Bytes
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
var template = require('./template'),
query = require('query'),
domify = require('domify'),
domTable = require('dom-table');
reactiveTable = require('reactive-table');
function Table (collection, renderer, scope, head) {
this.el = domify(template);
this.headEl = query('thead', this.el);
this.bodyEl = query('tbody', this.el);
this.reactiveTable = reactiveTable(collection, this.bodyEl, renderer, scope);
this.setHead(head);
return this;
};
Table.prototype.setHead = function (head) {
var rowEl,
cellEl,
i;
this.head = head;
domTable(this.headEl);
this.headEl.removeAllRows();
rowEl = this.headEl.addRow();
for (i in head) {
if (!head.hasOwnProperty(i))
continue;
rowEl.addCell(head[i].name || head[i]);
}
return this;
};
module.exports = function (collection, renderer, scope, head) {
return new Table(collection, renderer, scope, head);
};