From a046861c4a41ba0a3dab7af8656f30b13faedb94 Mon Sep 17 00:00:00 2001 From: aliounedia Date: Mon, 20 Jan 2014 23:33:34 +0100 Subject: [PATCH] [#384, slickgrid][s]: slickgrid add support for row-add and row-delete --- src/view.slickgrid.js | 2 -- test/view.slickgrid.test.js | 71 +++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/view.slickgrid.js b/src/view.slickgrid.js index 331ebef8..07faa048 100644 --- a/src/view.slickgrid.js +++ b/src/view.slickgrid.js @@ -1,4 +1,3 @@ - /*jshint multistr:true */ this.recline = this.recline || {}; @@ -477,4 +476,3 @@ my.SlickGrid = Backbone.View.extend({ $.extend(true, window, { Slick:{ Controls:{ ColumnPicker:SlickColumnPicker }}}); })(jQuery); -/*jshint multistr:true */ diff --git a/test/view.slickgrid.test.js b/test/view.slickgrid.test.js index 597461cd..80c895c6 100644 --- a/test/view.slickgrid.test.js +++ b/test/view.slickgrid.test.js @@ -103,6 +103,77 @@ test('editable', function () { view.remove(); }); +test('delete-row' , function(){ + var dataset = Fixture.getDataset(); + var view = new recline.View.SlickGrid({ + model: dataset, + state: { + hiddenColumns:['x','lat','title'], + columnsOrder:['lon','id','z','date', 'y', 'country'], + columnsWidth:[ + {column:'id',width: 250} + ], + gridOptions: {editable: true , "enabledDelRow":true}, + columnsEditor: [{column: 'country', editor: Slick.Editors.Text}] + } + }); + + $('.fixtures .test-datatable').append(view.el); + view.render(); + view.show(); + old_length = dataset.records.length + dataset.records.on('remove', function(record){ + equal(dataset.records.length, old_length -1 ); + }); + + // Be sure a cell change triggers a change of the model + e = new Slick.EventData(); + view.grid.onClick.notify({ + row: 1, + cell: 0, + grid: view.grid + }, e, view.grid); + + view.remove(); + + +}); + +test('add-row' , function(){ +//To test adding row on slickgrid , we add some menu GridControl +//I am based on the FlotControl in flot wiewer , to add a similary +//to the sclickgrid , The GridControl add a bouton menu +//one the .side-bar place , which will allow to add a row to +//the grid on-click + +var dataset = Fixture.getDataset(); + var view = new recline.View.SlickGrid({ + model: dataset, + state: { + hiddenColumns:['x','lat','title'], + columnsOrder:['lon','id','z','date', 'y', 'country'], + columnsWidth:[ + {column:'id',width: 250} + ], + gridOptions: {editable: true , "enabledAddRow":true}, + columnsEditor: [{column: 'country', editor: Slick.Editors.Text}] + } + }); + +// view will auto render ... +assertPresent('.recline-row-add', view.elSidebar); +// see recline.SlickGrid.GridControl widget +//view.render() +old_length = dataset.records.length +dataset.records.on('add',function(record){ + equal(dataset.records.length ,old_length + 1 ) +}); + +view.elSidebar.find('.recline-row-add').click(); + +}); + + test('update', function() { var dataset = Fixture.getDataset(); var view = new recline.View.SlickGrid({