Skip to content

Commit

Permalink
[datopian#131,slickgrid] Support renderers and derivers
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed May 30, 2012
1 parent 365b340 commit 1cffd8f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/view-slickgrid.js
Expand Up @@ -108,8 +108,15 @@ my.SlickGrid = Backbone.View.extend({
}
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);

Expand Down
29 changes: 28 additions & 1 deletion test/view-slickgrid.test.js
Expand Up @@ -42,7 +42,7 @@ test('state', function () {
var visibleColumns = _.filter(_.pluck(dataset.fields.toArray(),'id'),function(f){
return (_.indexOf(view.state.get('hiddenColumns'),f) == -1)
});

// Hidden columns
assertPresent('.slick-header-column[title="y"]');
assertNotPresent('.slick-header-column[title="x"]');
Expand All @@ -61,4 +61,31 @@ test('state', function () {
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);

0 comments on commit 1cffd8f

Please sign in to comment.