-
Notifications
You must be signed in to change notification settings - Fork 350
/
editable.js
65 lines (63 loc) · 1.86 KB
/
editable.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
// BEGIN-SNIPPET editable-controller
import Ember from 'ember';
import ColumnDefinition from 'ember-table/models/column-definition';
export default Ember.Controller.extend({
tableColumns: Ember.computed(function() {
var columnNames = ['open', 'close'];
var dateColumn = ColumnDefinition.create({
savedWidth: 100,
headerCellName: 'Date',
tableCellViewClass: 'date-picker-table-cell',
getCellContent: function(row) {
return row.get('date').toString('yyyy-MM-dd');
},
setCellContent: function(row, value) {
return row.set('date', value);
}
});
var ratingColumn = ColumnDefinition.create({
savedWidth: 150,
headerCellName: 'Analyst Rating',
tableCellViewClass: 'rating-table-cell',
contentPath: 'rating',
setCellContent: function(row, value) {
return row.set('rating', value);
}
});
var columns = columnNames.map(function(key) {
var name;
name = key.charAt(0).toUpperCase() + key.slice(1);
return ColumnDefinition.create({
savedWidth: 100,
headerCellName: name,
tableCellViewClass: 'editable-table-cell',
getCellContent: function(row) {
return row.get(key).toFixed(2);
},
setCellContent: function(row, value) {
return row.set(key, +value);
}
});
});
columns.unshift(ratingColumn);
columns.unshift(dateColumn);
return columns;
}),
tableContent: Ember.computed(function() {
var content = [];
var date;
for (var i = 0; i < 100; i++) {
date = new Date();
date.setDate(date.getDate() + i);
content.pushObject({
index: i,
date: date,
open: Math.random() * 100 - 50,
close: Math.random() * 100 - 50,
rating: Math.round(Math.random() * 4)
});
}
return content;
})
});
// END-SNIPPET