PDA

View Full Version : Combobox Store insert(0, record)



DeathPhoenix
5 Feb 2010, 1:59 PM
Hi, I have a combobox using json. I want to insert a new record at index 0, but it always add it at the end.
Here are the combobox settings:


store: comboboxSearchStore,
displayField: 'value',
hideLabel: true,
mode: 'local',
triggerAction: 'all',
emptyText: 'Search...',
selectOnFocus: true

Here is the code I use to add the record


var comboboxSearchRecord = Ext.data.Record.create( [
{name: 'value', type: 'string'}
]);
comboboxSearch.getStore().insert(0, new comboboxSearchRecord({
value: comboboxSearch.getValue()
}));


So, why is it inserting at the bottom like if I was using a simple add(record)?

Thank you

7 Feb 2010, 7:06 PM
is your store sorting?

DeathPhoenix
8 Feb 2010, 6:28 AM
Hi,

no the combobox is not sorting, or... I didn't set him to. He is as plain as you see my parameters. Did I make them wrong and I ask him to sort without knowing?

Anyway, any word goes down. A word starting by "a" will go at the bottom.
So, have an idea?

Thanks :)

8 Feb 2010, 6:29 AM
You set sorting in the data store, which I cannot see. :-

DeathPhoenix
8 Feb 2010, 6:31 AM
I just forgot to give you my store source. Here it is :



var comboboxSearchStore = new Ext.data.JsonStore({
autoDestroy: true,
url: 'db/searchedValues',
root: 'searched',
fields: ['value']
});

DeathPhoenix
9 Feb 2010, 1:13 PM
Hi,
(Update, not true, nothing to solve!)
just letting you know that I've updated to 3.1.1 (I was 3.1.0) and this issue is no longer there. Thanks for update. :D

9 Feb 2010, 1:14 PM
excellent!

DeathPhoenix
8 Apr 2010, 6:12 AM
Hi,

I now clearly understand the reason why I had this behavior. This is not an issue, but more like a forced behavior that can be "reverted".

I have a combobox that use the autocompletion feature. So will the user type, it show matchs. Great thing I must say. How does it work? When user type, it grab the combobox store and apply a filter directly on it. Good.

Now, I wanted to save searched value in the store when the user as hit a button. If the value was completely new (no possible match, let say "fsadadrgwerv" ;) ), the filter was "removing" all values from the store. So insert 0 was inserting in an empty store! When refiltering (next search), the value was at the bottom of the list.

To remove autocompletion filtering on your store before adding a new value (let say at a specific position...) do :


store.clearFilter(true);


Now, you can create a record and add it to position 0. (in case you don't know how!)


// Create new data
var newData = {
value: trimmedValue
};
// Add data to position 0. (don't use getTotalCount())
var recId = store.getCount();
var r = new store.recordType(newData, ++recId); // create new record
store.insert(0, r); // insert a new record into the store (also see add)