PDA

View Full Version : Assigning new store for combobox in editorgrid column



gabrieaj
28 Oct 2010, 1:19 AM
Hi,

I have a editor grid which has one of the columns as combo box editor.
Editor grid displays number of rows.

When the user adds new row, combo box needs to display only those values which are not displayed
in editor grid row.

Is there any way, I can assign new store to combo-box which will fetch the values from server side and it does not contain the values which are already displayed in editor grid rows ??

I have tried removing the values from the assigned store, however when i edit already displayed row, combobox values disappers..

Thanks for the help in advance.

Thanks & Regards,
Ajay

Condor
28 Oct 2010, 1:43 AM
You can filter or reload the store from the beforeedit event of the grid.

gabrieaj
28 Oct 2010, 6:03 AM
Thanks for quick reply.

I will need your expert assistance in creating filters on combo-box.

Below is my code which filters only one record:



var f = grid.getColumnModel().getCellEditor(0, grid.getStore().getCount()-1).field;
var fieldStore = f.store; //combobox store
fieldStore.clearFilter(false);
fieldStore.filterBy(function(record, id) {
var gridStore = grid.getStore();
Ext.each(gridStore, function(gridStore, index) {
var partnerCompanyId = gridStore.getAt(index).get('companyId');
if((partnerCompanyId != null) && (partnerCompanyId != 'undefined') && (partnerCompanyId != -1)) {
return (record.get('companyId') != partnerCompanyId);
}
});
return true;
});


Above code just filters out the first companyId from the combo-box. combo-box needs to filter out all the records in the grid.
Not sure, where i am going wrong.
Please help.

Condor
28 Oct 2010, 6:47 AM
The return statement inside your Ext.each loop only stops the loop, it doesn't return anything to the filterBy function.

You want:

var row = Ext.each(gridStore, function(gridStore, index) {
...
});
return Ext.isNumber(row);

gabrieaj
29 Oct 2010, 2:43 AM
got stuck again:

Here is my code:


applyFiltersToComboboxStore = function () {
var f = grid.getColumnModel().getCellEditor(0, grid.getStore().getCount()-1).field;
var fieldStore = f.store;
fieldStore.clearFilter(true);
fieldStore.filterBy(function(record, id) {

var index = gridStore.findBy(function(gridStoreRecord, id) {
return gridStoreRecord.get('companyId') == record.get('companyId');
});

if(index != -1) {
return false ; //got the company in grid so filter out from the comboboxlist.
}

return true;
});
};


above code is not filtering out the companynames in the combo-box list.
Also now the grid is not displaying the name which were present in the grid previously.

Not sure where i am going wrong..

Condor
29 Oct 2010, 2:56 AM
How about a bit more efficient code?

applyFiltersToComboboxStore = function () {
// Generate hash from existing companyIds
var companyIds = {};
grid.getStore().each(function(rec) {
companyIds[rec.get('companyId')] = true;
});
// Filter out the records that are in the hash
grid.getColumnModel().getCellEditor(0, grid.getStore().getCount() - 1).field.store.filterBy(function(rec) {
return !companyIds[rec.get('companyId')];
});
};

ps. Don't forget that your combobox has to be configured with the following config options, otherwise it will clear the filter again when first used:

triggerAction: 'all',
lastQuery: ''

Disclaimer: Completely untested code!

gabrieaj
29 Oct 2010, 4:41 AM
That works like a charm !!

Thanks Condor for your help.