Merge pull request #134 from amercader/master
Support for renderers and derivers on SlickGrid view
This commit is contained in:
@@ -108,8 +108,15 @@ my.SlickGrid = Backbone.View.extend({
|
|||||||
}
|
}
|
||||||
columns = columns.concat(tempHiddenColumns);
|
columns = columns.concat(tempHiddenColumns);
|
||||||
|
|
||||||
|
var data = [];
|
||||||
|
|
||||||
var data = this.model.currentDocuments.toJSON();
|
this.model.currentDocuments.each(function(doc){
|
||||||
|
var row = {};
|
||||||
|
self.model.fields.each(function(field){
|
||||||
|
row[field.id] = doc.getFieldValue(field);
|
||||||
|
});
|
||||||
|
data.push(row);
|
||||||
|
});
|
||||||
|
|
||||||
this.grid = new Slick.Grid(this.el, data, visibleColumns, options);
|
this.grid = new Slick.Grid(this.el, data, visibleColumns, options);
|
||||||
|
|
||||||
|
|||||||
@@ -61,4 +61,31 @@ test('state', function () {
|
|||||||
view.remove();
|
view.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('renderers', function () {
|
||||||
|
var dataset = Fixture.getDataset();
|
||||||
|
|
||||||
|
dataset.fields.get('country').renderer = function(val, field, doc){
|
||||||
|
return 'Country: ' + val;
|
||||||
|
};
|
||||||
|
|
||||||
|
var deriver = function(val, field, doc){
|
||||||
|
return doc.get('x') * 10;
|
||||||
|
}
|
||||||
|
dataset.fields.add(new recline.Model.Field({id:'computed'},{deriver:deriver}));
|
||||||
|
|
||||||
|
|
||||||
|
var view = new recline.View.SlickGrid({
|
||||||
|
model: dataset
|
||||||
|
});
|
||||||
|
$('.fixtures .test-datatable').append(view.el);
|
||||||
|
view.render();
|
||||||
|
|
||||||
|
// Render the grid manually
|
||||||
|
view.grid.init();
|
||||||
|
|
||||||
|
equal($(view.grid.getCellNode(0,view.grid.getColumnIndex('country'))).text(),'Country: DE');
|
||||||
|
equal($(view.grid.getCellNode(0,view.grid.getColumnIndex('computed'))).text(),'10');
|
||||||
|
view.remove();
|
||||||
|
});
|
||||||
|
|
||||||
})(this.jQuery);
|
})(this.jQuery);
|
||||||
|
|||||||
Reference in New Issue
Block a user