PDA

View Full Version : store getCount returns 0



vicvolk87
1 Jul 2013, 11:47 AM
Hi, Sencha super-stars!) Please, help if you know how. I have a combobox which has query mode set to 'remote'. Once the store is loaded and is not empty I want to change the mode dynamically to 'local', so that the user could do the search in the current store, not in the whole database. I tried to do it in this way:


Ext.getCmp('mycombo').store.on('load', function(e, t, eOpts) {
if(Ext.getCmp('mycombo').store.getCount()!=0)Ext.getCmp('mycombo').queryMode='local';
else Ext.getCmp('mycombo').queryMode='remote';
});


But the problem is Ext.getCmp('mycombo').store.getCount() always returns 0, even though I see that the store has changed. I tried "on('afterload'" but to no avail.
Thank you!!

vicvolk87
1 Jul 2013, 12:15 PM
Finally. I made it work:


Ext.getCmp('mycombo').store.on('load', function(e, t, eOpts) {
if(e.getCount()!=0)Ext.getCmp('mycombo').queryMode='local';
else Ext.getCmp('mycombo').queryMode='remote';
});


However, now I face another problem. Setting queryMode to 'local' does not have any effect. If the user continues typing, I still see server calls. But what I want is to locally search when the store is loaded. It would be great if youl could help me to do the trick.

Thank you so much!!

vicvolk87
1 Jul 2013, 12:24 PM
I also tried


Ext.apply(Ext.getCmp('mycombo'),{queryMode:'local'})


But it also has no effect. The queryMode still remains 'remote'.

skirtle
2 Jul 2013, 5:23 AM
Why do you have it set to remote in the first place?

I think you may have misunderstood the purpose of queryMode. You may find this explanation helpful:

http://skirtlesden.com/articles/extjs-comboboxes-part-2

vicvolk87
2 Jul 2013, 6:15 AM
Thank you for advice, Skirtle. The problem is, the store is too large to make it static. It may contain thousands of rows. A concrete example - I have a table of cities, this table has two columns - one is called "country" and another is "city". The idea is when the user starts typing for example "Russia" then the store is loaded with a bunch of rows (Russia Moscow; Russia St Petersburg, etc.) - and from this moment I want to make the store static, so that when the user continues typing, say, "Russia Mo..." he should get "Russia Moscow", because it is already in the store, and would not get "Mozambique Maputu". I searched on the web and found the idea of a hybrid combobox, but there is no working implementation for extjs 4.2.

skirtle
2 Jul 2013, 8:12 AM
Off the top of my head, you could maybe use the beforequery event to cancel the request and apply your own manual filter. A bit of trickery with lastQuery would probably be required to get it working reliably, you can't just use getCount.

vicvolk87
2 Jul 2013, 8:59 AM
getCount works good, at least when queryMode is set "remote". I guess the clue to the problem now is to switch between "my own filter" and standard behaviour of the combobox. I just thought that if I could change queryMode dynamically from 'remote' to' local' and virceversa there would be no need in any custom filters.
Thank you!