PDA

View Full Version : How to get groupField value after Grouping is change



AtulDawkhare
3 Oct 2011, 1:45 AM
Hi All,
I am using Grouping feature of the ExtJs. I want to delete on Right click the total Group.
I am able to find out.

In the below code I have marked in bold 'Customer' , currently I have put this hardcoded value.

It is possible that I will get the current's value after grouping changed?
Can you please guid?

Like in the below data, Default groupField= Customer, when I change to OrderPrice then i should get the Orderprice so something , so that I will be able to delete the whole group.

Please suggest if any other solution...
Store data


{Customer:'CustomerA',OrderPrice:'2000',ProductCode:'AABBDCCEE'},
{Customer:'CustomerA',OrderPrice:'1000',ProductCode:'AABBDCCEEDD'},
{Customer:'CustomerA',OrderPrice:'3000',ProductCode:'AABBDCCEEDD'},
{Customer:'CustomerB',OrderPrice:'4000',ProductCode:'AABBDCCEE'},



Menu code :-


groupcontextmenu:function (view,node,group,e,eOpts)
{

var menu= new Ext.menu.Menu();
menu.add({text:"Edit",icon: 'css/images/add16.gif',handler:
function()
{

//var my_record = view.getSelectionMode() ;
alert(value)
/*var my_record_param = 'name='+my_record.data['name']+'&group='+group;
var my_url = 'Test.jsp?' + my_record_param
new Ext.Window({
width: 500,
title:'New redirected window',
resizable :true,
minimizable :true,
height: 500,
closable: true,
html: '<iframe width="500" height="500" src="' + my_url + '"</iframe>'
}).show();
*/


}
});
menu.add({text:"Delete Record",handler://RowDelete(grid)
function()
{
alert(group)
var values= RestaurantStore.queryBy(function(record)
{
return record.get('Customer')==group
})

for(var i = 0, len = values.length; i < len; i++)
{
RestaurantStore.remove(values.getAt(i));
}
}
});
e.stopEvent();
menu.showAt(e.xy);

}




Extjs Grouping feature:-



var groupingFeature = Ext.create('Ext.grid.feature.Grouping',{
groupHeaderTpl: '{name} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})'
//startCollapsed:true
});

skirtle
3 Oct 2011, 9:01 AM
The groupField property of the store perhaps?

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store-property-groupField

AtulDawkhare
3 Oct 2011, 9:18 PM
Thanks for the reply.
The Group Field property returns the value that we have specified in the Store. i.e. default grouping.
But I want the value after the Grouping is changed.

Like When I define the store , the code is




var RestaurantStore = Ext.create('Ext.data.JsonStore', {
storeId: 'restaraunts',
model: 'Restaurant',
sorters:['ProductCode','OrderPrice','Customer'],
groupField: 'Customer',
data:[
{Customer:'CustomerA',OrderPrice:'2000',ProductCode:'AABBDCCEE'},
{Customer:'CustomerA',OrderPrice:'1000',ProductCode:'AABBDCCEEDD'},
{Customer:'CustomerA',OrderPrice:'3000',ProductCode:'AABBDCCEEDD'},
{Customer:'CustomerB',OrderPrice:'4000',ProductCode:'AABBDCCEE'},
{Customer:'CustomerB',OrderPrice:'4000',ProductCode:'AABBDCCEEFF'},
{Customer:'CustomerB',OrderPrice:'2000',ProductCode:'AABBDCCEEFF'},
{Customer:'CustomerC',OrderPrice:'2000',ProductCode:'AABBDCCEE'},
{Customer:'CustomerC',OrderPrice:'3000',ProductCode:'AABBDCCEEGG'},

]
});


In the above code my default Grouping will be on "Customer" column.

But I want if I regroup my Grid using say "ProductCode" [like in the given example ]

How will I get the Newly GroupField value i.e. "ProductCode" ??


Hope I am able to explain my query very well.

28496

twaindev
4 Oct 2011, 4:10 AM
Perhaps you can use the groupchange event of the store?

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store-event-groupchange

skirtle
4 Oct 2011, 11:59 AM
The Group Field property returns the value that we have specified in the Store. i.e. default grouping.
But I want the value after the Grouping is changed.

Agreed. I suspect there's a mistake in the docs and that property should actually be listed as a config option instead.

Seems you can get the grouper using:


store.groupers.first();

If you want the field name it would be:


store.groupers.first().property;

AtulDawkhare
5 Oct 2011, 12:00 AM
Hey Thanks a lot.. I was looking for this only