PDA

View Full Version : How to deleted whole Group from the Grid



AtulDawkhare
26 Sep 2011, 1:40 AM
Hi
I have code in which I am creating grid with Ext.grid.feature.Grouping feature.

Now I want to delete the whole grouped records on mouse right click.
28337

I want to delete all the 9 items of group "American", when I clicked on Delete option.
I am not able to figure out how to select all grouped records and delete them.


My currerent code is :-

var grid = Ext.create('Ext.grid.Panel', {
listeners:
{
groupcontextmenu:function (view,node,group,e,eOpts)
{

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

}
});
menu.add({text:"Delete Record",handler://RowDelete(grid)
function()
{
var sm = grid.getSelectionModel().getSelection();
alert(view)
alert(group)
alert(rows.length)
//Restaurants.remove(sm.getSelection());
}
});
e.stopEvent();
menu.showAt(e.xy);

}
},


Please suggest the solution for this.

AtulDawkhare
26 Sep 2011, 3:11 AM
Can anybody please help me?

skirtle
26 Sep 2011, 4:39 AM
Please use CODE tags when posting code (# button on the editor toolbar).

Please don't bump threads so quickly. You really shouldn't expect an answer within 91 minutes, you need to give it at least 24 hours just to give each timezone chance to read it.

The technique I'd use to delete a whole group is as follows:


Grab the value of the group field for the group you want to delete. You have a few options for ways you might do this. One way might be to grab the value of the group field from the selected record. An alternative would be to use the thrid argument passed to the groupcontextmenu event handler.
Use queryBy() (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store-method-queryBy) or similar to find all records with the same value in their group field. These should be all the members of the group.
Delete them from the store.

AtulDawkhare
26 Sep 2011, 6:04 AM
Thank you for the reply.

I am just learning the extjs and I tired on myself but not getting the syntax .So I would be very thankful if you show me the syntax for this queryBy().

Can you please give me some code example/samples how to use the Store.queryBy() method ?

skirtle
26 Sep 2011, 6:42 AM
It'd be something a bit like this:


var records = store.queryBy(function(record) {
return record.get('groupField') === groupValue;
});

where groupField should be replaced with the name of the relevant field and groupValue would be the value common to all members of the group.

It might actually be easier to do this using getGroups() instead of queryBy():

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