Skip to content

Commit

Permalink
Merge pull request datopian#388 from aliounedia/master
Browse files Browse the repository at this point in the history
[datopian#385]add row add delete support for reclinejs
  • Loading branch information
rufuspollock committed Feb 5, 2014
2 parents 2ccc162 + 39286dd commit 306c0e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 2 additions & 0 deletions demos/multiview/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ var createExplorer = function(dataset, state) {
gridOptions: {
editable: true,
enabledAddRow: true,
enabledDelRow: true,
autoEdit: false,
enableCellNavigation: true
},
columnsEditor: [
Expand Down
24 changes: 13 additions & 11 deletions src/view.slickgrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ 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
Expand Down Expand Up @@ -101,11 +98,10 @@ my.SlickGrid = Backbone.View.extend({
&& 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({})
this.listenTo(this.editor.state, 'change', function(){
this.model.records.add(new recline.Model.Record())
});
}

},
onRecordChanged: function(record) {
// Ignore if the grid is not yet drawn
Expand Down Expand Up @@ -150,9 +146,11 @@ my.SlickGrid = Backbone.View.extend({
var validator = function(field){
return function(value){
if(field.type == "date" && isNaN(Date.parse(value))){
return {valid: false, msg: "A date is required , check field field-date-format"};
return {
valid: false,
msg: "A date is required, check field field-date-format"};
}else {
return {valid: true, msg :null }
return {valid: true, msg :null }
}
}
};
Expand Down Expand Up @@ -230,12 +228,16 @@ my.SlickGrid = Backbone.View.extend({
}
}
columns = columns.concat(tempHiddenColumns);

// Transform a model object into a row
function toRow(m) {
var row = {};
self.model.fields.each(function(field){
row[field.id] = m.getFieldValueUnrendered(field);
var render = "";
//when adding row from slickgrid the field value is undefined
if(!_.isUndefined(m.getFieldValueUnrendered(field))){
render =m.getFieldValueUnrendered(field)
}
row[field.id] = render
});
return row;
}
Expand Down Expand Up @@ -304,7 +306,7 @@ my.SlickGrid = Backbone.View.extend({
this._slickHandler.subscribe(this.grid.onCellChange, function (e, args) {
// We need to change the model associated value
var grid = args.grid;
var model = data.getModel(args.row);
var model = data.getModel(args.row);
var field = grid.getColumns()[args.cell].id;
var v = {};
v[field] = args.item[field];
Expand Down

0 comments on commit 306c0e6

Please sign in to comment.