PDA

View Full Version : combo with default -- all -- option?



PCSpectra
8 Feb 2010, 5:45 AM
I have several comboboxes which are populated via a data store, all of which are database driven.

I have the requirement to offer a -- all -- option as the very first item in the drop down, so when selected, no filtering takes place.

How would I best accomplish this? leaving the text field blank/empty is one solution I suppose, and adding a initial -- all -- record to the database table is another, but ideally I'd rather add the element as the first item after the data store has populated the combo drop down, at least this seems least hackish in approach to me.

Cheers,
Alex

mzkr
8 Feb 2010, 6:12 AM
While getting data from server, add "--ALL--" option along with rest of data

PCSpectra
8 Feb 2010, 8:31 AM
I could, yes, but that solution feels hackish to me.

I would much rather poek that option into place using extJS as it's an interface specific functionality, not so much the duty responsibility of a web service.

Is there no DOM support or something, which I could use to poke the blank entry into the list at the afterrender event or something???

Cheers,
Alex

Remy
8 Feb 2010, 8:53 AM
you could add a record to the store after the db work is done. What I do is pass a parameter server side which then determines whether the returned data requires an 'ALL' option and pass it back with the response.

This means the business logic handles it where it should.

PCSpectra
9 Feb 2010, 5:51 PM
This means the business logic handles it where it should.

This is what I want to do, is simply insert an item into the store pre-render. Where would I best do something like this??? beforerender???



listeners: {
beforerender: function(){
this.store.insert(0, '-- ALL --');
}
}


Something like this???

Cheers,
Alex

Eugen_
9 Feb 2010, 11:07 PM
I do it like that


var storeForYourComboBox = new Ext.data.Store({
reader: new Ext.data.XmlReader({
record: 'test',
id: 'id'
}, [
{name: 'id', type: 'int'},
{name: 'title', type: 'string'}
]),
listeners: {
'load': function(store, records, options) {
var record = new store.recordType({
id: 0,
title: '-- ALL --'
});
store.insert(0, record);
}
}
});