Skip to content

Commit a046861

Browse files
committed
[datopian#384, slickgrid][s]: slickgrid add support for row-add and row-delete
1 parent 66daf6f commit a046861

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

src/view.slickgrid.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*jshint multistr:true */
32

43
this.recline = this.recline || {};
@@ -477,4 +476,3 @@ my.SlickGrid = Backbone.View.extend({
477476
$.extend(true, window, { Slick:{ Controls:{ ColumnPicker:SlickColumnPicker }}});
478477
})(jQuery);
479478

480-
/*jshint multistr:true */

test/view.slickgrid.test.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,77 @@ test('editable', function () {
103103
view.remove();
104104
});
105105

106+
test('delete-row' , function(){
107+
var dataset = Fixture.getDataset();
108+
var view = new recline.View.SlickGrid({
109+
model: dataset,
110+
state: {
111+
hiddenColumns:['x','lat','title'],
112+
columnsOrder:['lon','id','z','date', 'y', 'country'],
113+
columnsWidth:[
114+
{column:'id',width: 250}
115+
],
116+
gridOptions: {editable: true , "enabledDelRow":true},
117+
columnsEditor: [{column: 'country', editor: Slick.Editors.Text}]
118+
}
119+
});
120+
121+
$('.fixtures .test-datatable').append(view.el);
122+
view.render();
123+
view.show();
124+
old_length = dataset.records.length
125+
dataset.records.on('remove', function(record){
126+
equal(dataset.records.length, old_length -1 );
127+
});
128+
129+
// Be sure a cell change triggers a change of the model
130+
e = new Slick.EventData();
131+
view.grid.onClick.notify({
132+
row: 1,
133+
cell: 0,
134+
grid: view.grid
135+
}, e, view.grid);
136+
137+
view.remove();
138+
139+
140+
});
141+
142+
test('add-row' , function(){
143+
//To test adding row on slickgrid , we add some menu GridControl
144+
//I am based on the FlotControl in flot wiewer , to add a similary
145+
//to the sclickgrid , The GridControl add a bouton menu
146+
//one the .side-bar place , which will allow to add a row to
147+
//the grid on-click
148+
149+
var dataset = Fixture.getDataset();
150+
var view = new recline.View.SlickGrid({
151+
model: dataset,
152+
state: {
153+
hiddenColumns:['x','lat','title'],
154+
columnsOrder:['lon','id','z','date', 'y', 'country'],
155+
columnsWidth:[
156+
{column:'id',width: 250}
157+
],
158+
gridOptions: {editable: true , "enabledAddRow":true},
159+
columnsEditor: [{column: 'country', editor: Slick.Editors.Text}]
160+
}
161+
});
162+
163+
// view will auto render ...
164+
assertPresent('.recline-row-add', view.elSidebar);
165+
// see recline.SlickGrid.GridControl widget
166+
//view.render()
167+
old_length = dataset.records.length
168+
dataset.records.on('add',function(record){
169+
equal(dataset.records.length ,old_length + 1 )
170+
});
171+
172+
view.elSidebar.find('.recline-row-add').click();
173+
174+
});
175+
176+
106177
test('update', function() {
107178
var dataset = Fixture.getDataset();
108179
var view = new recline.View.SlickGrid({

0 commit comments

Comments
 (0)