From 66daf6f36f75113d314d6cca5ff4d12bc14a91b0 Mon Sep 17 00:00:00 2001 From: aliounedia Date: Mon, 20 Jan 2014 23:28:37 +0100 Subject: [PATCH] [#384, slickgrid][s]: slickgrid add support for row-add and row-delete --- src/view.slickgrid.js | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/view.slickgrid.js b/src/view.slickgrid.js index d4c08b07..331ebef8 100644 --- a/src/view.slickgrid.js +++ b/src/view.slickgrid.js @@ -1,3 +1,4 @@ + /*jshint multistr:true */ this.recline = this.recline || {}; @@ -6,6 +7,8 @@ this.recline.View = this.recline.View || {}; (function($, my) { "use strict"; + + // Add new grid Control to display a new row add menu bouton // It display a simple side-bar menu ,for user to add new // row to grid @@ -33,7 +36,7 @@ this.recline.View = this.recline.View || {}; addNewRow : function(e){ e.preventDefault() - this.state.set({"newrow" : "pending"}) + this.state.trigger("change") } } ); @@ -76,20 +79,9 @@ my.SlickGrid = Backbone.View.extend({ this.templates = { "deleterow" : 'X' } - - //add menu for new row - this.editor = new my.GridControl() - this.elSidebar = this.editor.$el - - _.bindAll(this, 'render', 'onRecordChanged'); this.listenTo(this.model.records, 'add remove reset', this.render); this.listenTo(this.model.records, 'change', this.onRecordChanged); - this.listenTo(this.editor.state, 'change', function(){ - this.model.records.add({}) - this.editor.state.set({"newrow" : "done"}) - }); - var state = _.extend({ hiddenColumns: [], columnsOrder: [], @@ -103,6 +95,18 @@ my.SlickGrid = Backbone.View.extend({ ); this.state = new recline.Model.ObjectState(state); this._slickHandler = new Slick.EventHandler(); + + //add menu for new row , check if enableAddRow is set to true or not set + if(this.state.get("gridOptions") + && this.state.get("gridOptions").enabledAddRow != undefined + && this.state.get("gridOptions").enabledAddRow == true ){ + this.editor = new my.GridControl() + this.elSidebar = this.editor.$el + this.listenTo(this.editor.state, 'change', function(){ + this.model.records.add({}) + }); + } + }, onRecordChanged: function(record) { // Ignore if the grid is not yet drawn @@ -153,16 +157,19 @@ my.SlickGrid = Backbone.View.extend({ } } }; - //Add row delete support + //Add row delete support , check if enableDelRow is set to true or not set + if(this.state.get("gridOptions") + && this.state.get("gridOptions").enabledDelRow != undefined + && this.state.get("gridOptions").enabledDelRow == true ){ columns.push({ id: 'del', name: 'del', field: 'del', sortable: true, - width: 10, + width: 80, formatter: formatter, validator:validator - }) + })} _.each(this.model.fields.toJSON(),function(field){ var column = { id: field.id, @@ -470,3 +477,4 @@ my.SlickGrid = Backbone.View.extend({ $.extend(true, window, { Slick:{ Controls:{ ColumnPicker:SlickColumnPicker }}}); })(jQuery); +/*jshint multistr:true */