PDA

View Full Version : How accept editor to grid on fly(online)



Denin2004
6 Mar 2012, 11:35 AM
Hi!
I try create dynamic configured grid.
When I try accept Ext.grid.plugin.RowEditing : it not work property...
I get error (see printscreen on attachment).

Help me, please.
Best regards, Denis.


My code:


Ext.define('UsersApp.lib.myGrid' ,{
extend: 'Ext.grid.Panel',
alias: 'widget.myGrid',
title : 'All Users',
objectName: '',
dataSet: '',
columns: [],
configLoaded: false,
loadConfig: loadConfig,
getConfig: getConfig
});

function loadConfig()
{
Ext.Ajax.request({url : 'MyURL',
callback:this.getConfig,
scope:this});
}

function getConfig(options, success, response)
{
if(success)
{
var res = Ext.JSON.decode(response.responseText);
if(typeof(extJSObjects[res.dataSet]) == 'undefined')
{
Ext.define(res.dataSet,res.model);
extJSObjects[res.dataSet] = true;
}
this.columns = res.grid.columns;
this.plugins = [Ext.create('Ext.grid.plugin.RowEditing', {clicksToEdit: 2})];
res.store.proxy.api = {};
var toolbar = {xtype: 'toolbar',items:[]};
res.store.proxy.api.read = 'MyURLRead';
if(res.editFlags.update)
res.store.proxy.api.update = 'MyURLUpdate';
if(res.editFlags.insert)
{
res.store.proxy.api.create = 'MyURLInsert';
toolbar.items[0] ={text: 'Create',iconCls: 'icon-add',handler :insertData,scope:this};
}
if(res.editFlags.del)
{
res.store.proxy.api.destroy = 'MyURLDelete';
toolbar.items[toolbar.items.length] ={text: 'Delete',iconCls: 'icon-add',handler:confirmDeleteRecord,scope:this};
}
if(toolbar.items.length != 0) this.addDocked(toolbar);
var store = Ext.create('Ext.data.Store',res.store);
store.on('load',function(){this.reconfigure(store,this.columns);}, this);
store.autoLoad = true;
store.load();
this.configLoaded = true;
}
else alert('Error!!!');
}

function confirmDeleteRecord(grid)
{
this.selection = this.getView().getSelectionModel().getSelection()[0];
if(this.selection)
Ext.MessageBox.confirm('Confirm', 'Delete record?',deleteRecord,this)
else
Ext.MessageBox.alert('Status', 'No selected!!!');
}

function deleteRecord()
{
this.getStore().remove(this.selection);
}

function insertData()
{
this.getStore().insert(0,Ext.create(this.dataSet));
this.plugins[0].startEdit(0, 0);
}

My configuration JSON (response to getConfig)

{
"dataSet": "Params",
"editFlags":{"update":true,"del":true,"insert":true},
"model":{
"extend": "Ext.data.Model",
"idProperty": "fld6",
"fields": [{"name":"fld6","key":"cd6"},{"name":"fld7"}]},
"store":{"model":"Params",
"autoLoad": false,
"autoDestroy": true,
"autoSync": true,
"proxy":{"type":"ajax",
"reader":{"type":"json",
"root":"rows",
"idProperty": "fld6"},
"writer":{"type":"json",
"root":"rows",
"writeAllFields": false}}},
"grid":{"columns":[{"header":"id",
"dataIndex":"fld6",
"editor": "textfield"},
{"header":"Name",
"dataIndex":"fld7",
"width":300,
"editor": {
"xtype": "textfield",
"allowBlank": false}}]}
}

mitchellsimoens
6 Mar 2012, 12:33 PM
The plugins should be created in the initComponent of the class. If they are not there then they may not be created correctly and you would have to handle that.

Denin2004
6 Mar 2012, 1:11 PM
Great!!! It's worked!!!!
Thank you!!!
I have another question: When I try add record, grid store immediately call ajax request to insert url...
How can I disable this?

mitchellsimoens
6 Mar 2012, 1:14 PM
do you have autoSync set to true on the store?

Denin2004
6 Mar 2012, 1:27 PM
Yes... You mean that then user add record, I must set autosync to false?

mitchellsimoens
6 Mar 2012, 1:29 PM
If you don't want it to send the sync request automatically then you should leave autoSync to it's default of false. You would then need to call sync() where you want the sync request to happen.

Denin2004
6 Mar 2012, 1:42 PM
OK... I understood... I want "delete" - autosync operation... "insert, update" - on change selected row(with confirmation)... I would experiment with this..
Thank you!!!!
Last question: how I can mark this thread as "answered"?

mitchellsimoens
7 Mar 2012, 4:58 AM
At the top-right of each post there should be a Mark Best Answer link that will mark that post as the best answer.