PDA

View Full Version : Can I put condition in dataIndex?



gigas01
25 Sep 2012, 11:38 AM
Hi all,

This is what i'm getting from the server side

38924

and this is the displaying ui
38925

Here, you can see two columns Immediate Res~, Extended Res

if the column 'pre' is 1, i want to put in to Immediate Res

and if the column 'pre' is 2, i want to put in to Extended Res.

Is there are good solution about this?

I have tought about this for all day, but couldn't solve it :(

This is the full code.



var comboLoader = new MyApp.plugins.comboLoader();
MyApp.JobActionSummary = Ext.extend(MyApp.CardPanel, {
itemId : 'chain-err-job-action-summary',
layout : 'floating-form',
url : MyApp.getApiUrl('JobActionsFinalSummaryController'),
autoScroll : true,
height : 400,
padding : '20',
// defaults: { border: false },


labelAlign : 'top',
constructor : function(cfg) {
cfg = MyApp.constructorHelper(this, cfg);
MyApp.chainErrJobAction.superclass.constructor.call(this, cfg);
},
createItems : function() {
var formItems = [];
var store = new Ext.data.JsonStore({
// fields: ['ID','Name','reportToICRole','action'],
fields : [ 'Name', 'reportToICRole', 'action' ],
url : MyApp.getApiUrl('JobActionsFinalSummaryController'),
writer : new Ext.data.JsonWriter(),
root : 'data',
// idProperty: 'ID'
});
var rowActions = new MyApp.RowActions({
autoWidth : false,
header : 'Action',


width : 100,
actions : [ {
iconCls : 'icon-edit',
tooltip : 'Edit',
text : 'Edit'
}, {
iconCls : 'icon-delete',
tooltip : 'Delete',
text : 'Delete'
} ]
});
rowActions.on('action', this.onRowAction, this);


// formItems.push({ xtype: 'MyApp-Heading', html:'Job Action
// Summary'+'<br><br>'});
// formItems.push({ xtype: 'MyApp-normalText', html:'Here is the job
// action information you have inputted thus far. You can add,
// edit(change), or delete job action information.'});
formItems.push({
xtype : 'box',
width : 800,
html : '<br><br>'
});


formItems.push({
xtype : 'editorgrid',
autoHeight : true,
autoWidth : true,
store : store,
title : 'Job Actions Summary',
id : 'grid1',
ref : 'grid1',
plugins : [ rowActions, comboLoader ],
clicksToEdit : 1,
anchor : '-18',
tbar : {
buttonAlign : 'left',
items : [ {
iconCls : 'icon-add',
text : 'Add Job action',
handler : this.goBack,
scope : this
} ]
},
columns : [ new Ext.grid.RowNumberer({
width : 30
}), {
id : 'position',
header : 'Position',
width : 250,
dataIndex : 'Name',
editor : new Ext.form.TextField({
allowBlank : true
})
}, {
id : 'reportsTo',
header : 'Reports To',
width : 150,
dataIndex : 'reportToICRole',
editor : new Ext.form.TextField({
allowBlank : false
})
}, {
id : 'immres',
header : 'Immediate Responsibilities',
width : 150,
dataIndex : 'action',
editor : new Ext.form.TextField({
allowBlank : false
})
}, {
id : 'extres',
header : 'Extended Responsibilities',
width : 150,
dataIndex : 'action',
editor : new Ext.form.TextField({
allowBlank : false
})
}, rowActions ]
});


formItems.push({
xtype : 'box',
width : 800,
html : '<br><br>'
});


return formItems;
},


onAddStaff : function(name, role) {


document.location.hash = "#chain-err-job-action|name=" + name
+ "&role=" + role;
// how should i send the parameter(name) to the next page?
},


onRowAction : function(grid, record, action) {
this.activeRecord = record;
switch (action) {
case "icon-delete":
this.goBack();
break;
case "icon-edit":
this.onAddStaff(record.get('Name'), record.get('reportToICRole'));
break;
}
},


goBack : function() {
document.location.hash = "#chain-err-job-action";
},


loadPanel : function() {
this.grid1.getStore().load({
params : {
action : 'list'
},
scope : this
});
}


});
Ext.reg('MyApp-chain-err-job-action-summary', MyApp.JobActionSummary);

scottmartin
25 Sep 2012, 3:02 PM
Have you tried something like:

dataindex: (condition) ? 'field1' : 'field2'

Scott.

gigas01
26 Sep 2012, 5:44 AM
Thank you for the reply, but i think it has a little problem.

dataindex: (condition) ? 'field1' : 'field2'

in the condition i can't use the conditions that i want.

i want to use one of the stored data, but when i check breakpoint, i think it is not yet loaded.

so i can't check the condition :(

scottmartin
26 Sep 2012, 5:49 AM
I would suggest creating separate column objects and use grid.reconfigure() to make the changes as needed.

Scott.