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

grid grouping question

1 Answer 37 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 28 Jan 2013, 08:24 PM

I've got the following grid with grouping setup. I'd like it so that they can't remove the category group but can add and remove the other 3 .

Is that possible?   thanks



<telerik:RadGrid ID="RadGrid1"  runat="server" PageSize="50"
    AllowSorting="True" AllowMultiRowSelection="True" AllowPaging="false" ShowGroupPanel="True" OnPageIndexChanged="RadGrid1_OnPageIndexChanged"
    AutoGenerateColumns="False" GridLines="none" OnNeedDataSource="RadGrid1_OnNeedDataSource">
    <PagerStyle Mode="NextPrevNumericAndAdvanced"></PagerStyle>
    <MasterTableView Width="100%" >
        <GroupByExpressions >
             
            <telerik:GridGroupByExpression >
            <SelectFields>
                <telerik:GridGroupByField FieldAlias="Category" FieldName="Category"  />                  
            </SelectFields>
                <GroupByFields>
                    <telerik:GridGroupByField FieldName="Category"  SortOrder="Ascending"    />
                </GroupByFields>
            </telerik:GridGroupByExpression>
        </GroupByExpressions>
        <Columns>
            <telerik:GridBoundColumn SortExpression="PatientName" HeaderText="PatientName" HeaderButtonType="TextButton" DataField="PatientName"  Groupable="false"  />
            <telerik:GridBoundColumn SortExpression="Category" HeaderText="Category" HeaderButtonType="TextButton"  DataField="Category"  />
            <telerik:GridBoundColumn SortExpression="LastTaskTime"  HeaderText="LastTaskTime" HeaderButtonType="TextButton" DataField="LastTaskTime"  />
            <telerik:GridBoundColumn SortExpression="CaseStatus" HeaderText="CaseStatus" HeaderButtonType="TextButton" DataField="CaseStatus" />
        </Columns>
    </MasterTableView>
    <ClientSettings ReorderColumnsOnClient="True" AllowDragToGroup="True" AllowColumnsReorder="True" >
        <Selecting AllowRowSelect="True" ></Selecting>
        <Resizing AllowRowResize="True" AllowColumnResize="True" EnableRealTimeResize="True"
            ResizeGridOnColumnResize="False"></Resizing>
    </ClientSettings>
    <GroupingSettings ShowUnGroupButton="false">
     
    </GroupingSettings>
</telerik:RadGrid>

1 Answer, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 31 Jan 2013, 07:59 AM
Hello Steven,

To achieve the desired functionality you could try handling the RadGrid.GroupsChanging event and cancel it if the group by field is Category:
protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
 
        RadGrid1.GroupsChanging += RadGrid1_GroupsChanging;
    }
 
    void RadGrid1_GroupsChanging(object sender, GridGroupsChangingEventArgs e)
    {
        if (e.Expression.GroupByFields[0].FieldName == "Category")
        {
            e.Canceled = true;
        }
    }

Additionally I am sending you a simple example which demonstrates the suggested approach. Please check it out and let me know if it helps you.

Kind regards,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Steven
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Share this question
or