This is a migrated thread and some comments may be shown as answers.

[Solved] Prevent Grid ungroup

2 Answers 196 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cloud
Top achievements
Rank 1
Cloud asked on 04 Feb 2010, 03:10 AM
Hi all,

  I create a default grouping in a grid and don't want the user to remove that grouping, but they can still add another grouping after the default grouping. Is there any method that can prevent the user to remove the default grouping?

  Thx.

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Feb 2010, 04:44 AM
Hello Cloud,

Attach clientside OnCommand event to grid and check for the CommandName and CommandArgument to cancel the event according to your requirement.

The example below shows preventing ungrouping of first grouping which is already set.

JavaScript:
 
    function OnCommand(sender, args) { 
        if (args.get_commandName() == "UnGroupByExpression" && args.get_commandArgument() == "0:0") { 
            args.set_cancel(true); // Cancel the event 
        } 
    } 

-Shinu.
0
Cloud
Top achievements
Rank 1
answered on 04 Feb 2010, 06:23 AM
Hi Shinu,

  Your method works but there is a problem after the user swap the grouping order.
  I got a solution on the server side event, but don't know if it can be prevented in client side. Thx.

   protected void Grid_GroupsChanging(object source, GridGroupsChangingEventArgs e)  
    {  
        if (e.Action == GridGroupsChangingAction.Ungroup)  
        {  
            if (e.Expression.GroupByFields[0].FieldName == "ColumnName")  
                e.Canceled = true;  
        }  
    } 
Tags
Grid
Asked by
Cloud
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Cloud
Top achievements
Rank 1
Share this question
or