PDA

View Full Version : Saving empty record when using RowEditor



Chupa
2 Aug 2010, 6:38 AM
Hello.

I'm using RowEditor with my grid.
I have a RESTful datasource. When i click a new button, roweditor appears and try to save empty record.
I see an ajax request in firebug. I don't want to save empty record. I want to save only when save button pressed.

What i am doing wrong?

Code:

Ext.namespace('SMC.components');

SMC.components.ResourceGrid = Ext.extend(Ext.grid.GridPanel, {
initComponent: function() {
var self = this;
var editor = new Ext.ux.grid.RowEditor({});

Ext.applyIf(this, {
iconCls: 'icon-grid',
frame: true,
autoScroll: true,
width: 800,
height: 300,
plugins: [editor],
tbar: [
{
text: 'New',
iconCls: 'silk-add',
handler: function() {
this.addRecord.call(this);
},
scope: this
},
'-',
{
text: 'Delete',
iconCls: 'silk-delete',
handler: function() {
this.deleteRecord.call(this);
},
scope: this
}
],
viewConfig: {
forceFit: true
},
deleteRecord: function() {
var rec = this.getSelectionModel().getSelected();
if (!rec) {
return false;
}
this.store.remove(rec);
},
addRecord: function() {
var Dummy = Ext.data.Record.create(this.model.getFields());

editor.stopEditing();
this.store.insert(0, new Dummy({}));
this.getView().refresh();
editor.startEditing(0);
}
});

SMC.components.ResourceGrid.superclass.initComponent.call(this);
}
});

Condor
2 Aug 2010, 7:45 AM
Configure your record so it returns isValid() == false for records that shouldn't be saved yet (you could do this by configuring one or more fields with allowBlank:false).

Chupa
2 Aug 2010, 11:45 AM
Configure your record so it returns isValid() == false for records that shouldn't be saved yet (you could do this by configuring one or more fields with allowBlank:false).

Thanks a lot. It works.