PDA

View Full Version : Ext.data.store's grouping



inoabrian
4 Jun 2014, 5:59 AM
How does Ext.data.store's group method work?
If I group my store's 'Description' column. What will I get in return if I do store.getGroup('Description');
Also Could someone help me with setting up the store's group.
Could I do it in the Store's config? Or should I do it where I need it with a function call?

I would appreciate a quick syntactical example thanks.

arthurakay
9 Jun 2014, 7:46 AM
Well, let's take your questions in the wrong order:



If I group my store's 'Description' column. What will I get in return if I do store.getGroup('Description');


Nothing. The "store.getGroup('Description') method doesn't actually exist in Ext JS 4.2, so it will throw an error.



Could I do it in the Store's config? Or should I do it where I need it with a function call?


Yes, you can setup the store's grouping in the "groupField" config on the store... but if you're using a grid, you also need to turn on the grouping "feature".

See:
- http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.data.Store-cfg-groupField
- http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.grid.Panel-cfg-features
- http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.grid.feature.Grouping
- http://docs.sencha.com/extjs/4.2.2/#!/example/build/KitchenSink/ext-theme-neptune/#grouped-grid



How does Ext.data.store's group method work?


Looking at the API docs and raw code for store.group():
- http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.data.Store-method-group
- http://docs.sencha.com/extjs/4.2.2/source/Store.html#Ext-data-Store-method-group

...what you'll see is that the store accepts any defined "groupers" in order to reorganize its data. Nothing gets returned from the method, the data is simply shuffled/sorted according to the groupers passed. In the event that the store is remotely loaded and/or buffered, the store may reset to page 1.

-----

Here's a quick example I put together: https://fiddle.sencha.com/#fiddle/6gh

Does that answer your questions?