PDA

View Full Version : CheckColum - save row on (un)checking the checkbox



cipa
23 Feb 2011, 6:54 AM
Hi,

Just wandering if this is the correct solution to save a Grid row when a CheckColum is clicked. Are there any other ways to do this?


var cb = new Ext.ux.grid.CheckColumn({
header: _('survey.active')
,dataIndex: 'active'
,width: 40
,sortable: true
,onMouseDown: function(e, t){


var rowData = "";//holds the data to be sent
//checks/unchecks
if(t.className && t.className.indexOf('x-grid3-cc-'+this.id) != -1){
e.stopEvent();
var index = this.grid.getView().findRowIndex(t);
var record = this.grid.store.getAt(index);
record.set(this.dataIndex, !record.data[this.dataIndex]);
rowData = record.data;//save row records. will be used in the ajax request
}

/*
!!!seems that this is triggered by a row click and checkbox click
don't send the ajax request if the rowData is empty. rowData is empty if the row is clicked.
*/
if(rowData){
//send ajax request to update the data
Ext.Ajax.request({
url : Survey.config.connectorUrl ,
params : { action : 'mgr/survey/updateFromGrid', data: Ext.util.JSON.encode(rowData)},
method: 'POST',
success: function ( result, request ) {
//Ext.MessageBox.alert('Success', 'Data return from the server: '+ result.responseText);
//console.log(1);
},
failure: function ( result, request) {
//Ext.MessageBox.alert('Failed', result.responseText);
//console.log(0);
}
});
}
}
});


Thank you

cipa
23 Feb 2011, 2:59 PM
Hi,

Another solution is to somehow trigger the save_action: 'myAction' in the Grid.
Any ideas on how I can target the grid.

Here's the code


Ext.applyIf(config,{
id: 'survey-grid-survey'
,url: Survey.config.connectorUrl
,baseParams: { action: 'mgr/survey/getList' }
,fields: ['id','name','description','active','menu']
,paging: true
,remoteSort: true
,anchor: '95%'
,autoExpandColumn: 'name'
,save_action: 'mgr/survey/updateFromGrid'
,autosave: true
,plugins: [cb]
,columns: [{
header: _('id')
,dataIndex: 'id'
,sortable: true
,width: 60
},{
header: _('survey.name')
,dataIndex: 'name'
,sortable: true
,width: 100
,editor: { xtype: 'textfield' }
},{
header: _('survey.description')
,dataIndex: 'description'
,sortable: false
,width: 350
,editor: { xtype: 'textfield' }
}, cb]
,tbar:[{
xtype: 'textfield'
,id: 'survey-search-filter'
,emptyText: _('survey.search...')
,listeners: {
'change': {fn:this.search,scope:this}
,'render': {fn: function(cmp) {
new Ext.KeyMap(cmp.getEl(), {
key: Ext.EventObject.ENTER
,fn: function() {
this.fireEvent('change',this);
this.blur();
return true;
}
,scope: cmp
});
},scope:this}
}

}
,{
text: _('survey.survey_create')
,handler: { xtype: 'survey-window-survey-create' ,blankValues: true }
}]


});
Survey.grid.Survey.superclass.constructor.call(this,config)
Thank you

Condor
24 Feb 2011, 7:37 AM
Instead of overriding CheckColumn, I would listen for the store 'update' event and check if the 'active' field was changed to false.

x10
10 Mar 2011, 11:52 PM
I replaced BooleanColumn created by Ext Designer with CheckColumn at runtime. See

http://www.sencha.com/forum/showthread.php?116082-SOLVED-Convert-BooleanColumn-to-CheckColumn-in-EditorGridPanel/page2

but i can not catch any event from CheckColumn. Even store's 'update' doesn't fire on CheckColumn change. (?!)

d0vijay
24 Sep 2013, 4:08 PM
working on the checkcolumn having few cells rendered with '' empty and few having checkboxes, in this scenario how to avoid the click events on the empty cells

willigogs
26 Sep 2013, 7:59 AM
I've not used the checkColumn plugin before - but I would imagine you must be able to interrogate the event object during cell click to detect what the target was? If the target isn't a checkbox, then don't run the selected code.