PDA

View Full Version : Combo with remote store in a grid



vinitasharma11
1 Feb 2011, 6:46 AM
I have a grid with remote store. The grid has 3 columns User, Fee Amount, and Percentage. The User column is a combo box with a remote store. I somehow cannot get thsi to work. Here is a snapshot of the code. Anyhelp regarding this will be highly appreciated.


var fm = Ext.form;
var cm = new Ext.grid.ColumnModel({
defaults: {
sortable: true},
columns: [
{
header: 'Fee',
dataIndex: 'Fee',
width: 120,
// use shorthand alias defined above
editor: new fm.TextField({
allowBlank: false
})
},
{
header: 'FullName',
dataIndex: 'Id',
width: 200,
renderer: comboRenderer,
editor: new fm.ComboBox({
typeAhead: true,
triggerAction: 'all',
store: userStore,
displayField: 'FullName',
valueField: 'Id',
lazyRender: true,
emptyText: 'Select user'
,
}
})
?
},
{
header: 'Percent',
dataIndex: 'Percent',
width: 120,
editor: new fm.TextField({
allowBlank: false
})
}
]
});

var jmastore = new Ext.data.JsonStore({
autoLoad: false,
url: '../Job/GetGridData',
root: 'data',
fields: [{ name: 'InternalId', type: 'string' },
{ name: 'Id' },
{ name: 'FullName' },
{ name: 'Fee', type: 'string' },
{ name: 'Percent', type: 'string'}],
baseParams: { jobId: hdnJobId }
});


var userStore = new Ext.data.JsonStore({
autoLoad: false,
url: '../User/GetUsers',
fields: ["Id", "FullName"],
baseParams: { userId: 'Id', userName: '' }
});

function comboRenderer(val, p, record) {
userStore.load({ params: { userId: val, userName: ''} });
return (userStore.items[0]) ? userStore.items[0].data.FullName : '';
}

Condor
1 Feb 2011, 7:04 AM
load() is asynchronous, so you can't use it in a renderer.

Is the user database very big?

In that case I recommend adding another field to your store and have your server also send the username. Next, put the username editor on the username field and write an afteredit event handler that also sets the user id.

If it's small then you should preload the userStore and use a combocolumn (see Feature Requests section).

vinitasharma11
1 Feb 2011, 7:13 AM
Thanks Condor. I appreciate your help.

The user database is not very big; just 1000 rows. So I guess I will preload it.

In the combo editor I am using dataindex Id ( from the grid store), is that correct? Or should I be using Full Name. Since I am using Id as the dataindex, as soon as I click on combo it starts showing the Id. Then I have to delete that and start typing the username.

Condor
1 Feb 2011, 7:27 AM
Didn't realize you already included the FullName in the grid dataset, so the first solution would seem more appropriate.

If you intend on using the second solution, then using dataIndex:'Id' is indeed correct.