PDA

View Full Version : ComboBox Store -> How to sort after filters are applied? Solution should be easy.



elmn8r
24 Nov 2010, 7:23 AM
Solution should be easy, but I can't seem to figure this one out. I'm using Ext 3.2.1 (if that should matter at all).

I have a ComboBox that has a filter on it. When the user enters their 'query' into the ComboBox's input field, the filter gets applied and goes through the 'local' ArrayStore and filters out any items that don't have at least one match (anyMatch is set to true on the filter).

Here's where my problem rears its ugly head.

Let's say my ArrayStore has these items in it: 'Arkansas, Alabama, Kansas, Kentucky, Washington'

And the user has typed 'k' into the ComboBox, the drop-down looks like this:

Arkansas
Kansas
Kentucky

but that's not what I need. I need the Records to be sorted by 'startsWith' first, then 'anyMatch: true' after that.

If a user types 'k' into the ComboBox, I'd expect the drop-down to look like this:

Kansas
Kentucky
Arkansas

Is there something simple I'm missing to sort the records by 'startsWith' first then 'anyMatch' after a filter is applied to the store??

Thanks for any help.

elmn8r
24 Nov 2010, 9:56 AM
bump

Condor
25 Nov 2010, 8:06 AM
That seems a bit unpractical for the user.

Wouldn't it be better to show the list in the original alphabetic order, but highlight the first 'K' city (you'll have to override ComboBox onLoad behaviour for this).

elmn8r
25 Nov 2010, 6:05 PM
That seems a bit unpractical for the user.

Wouldn't it be better to show the list in the original alphabetic order, but highlight the first 'K' city (you'll have to override ComboBox onLoad behaviour for this).

If you type 'k' into a state combobox, you'd expect 'Arkansas' to show up first? Not all states that begin with the letter 'k'? Then as you type more, the choices in the drop-down drill down to match more what you are typing?

It makes more sense to me to have the choices that most match what the user is typing first, then have any 'partial' matches after that in the list. It just appears that there's no obvious way to produce this with the Ext combobox configurations.

Maybe I could set 'anyMatch: true' for the filter, and then on the 'datachanged' event sort the list manually?

Condor
26 Nov 2010, 12:48 AM
You would need to do a custom filter (if you do the filtering yourself you can combine it with sorting).

For this you need to override ComboBox.doQuery and to perform the filtering yourself you have to do what Store.filterBy currently does, but use your own queryBy.

elmn8r
26 Nov 2010, 7:38 AM
You would need to do a custom filter (if you do the filtering yourself you can combine it with sorting).

For this you need to override ComboBox.doQuery and to perform the filtering yourself you have to do what Store.filterBy currently does, but use your own queryBy.

Thanks so much Condor! I've overriden the doQuery method to achieve the proper drop-down order that I want.