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

RadGrip Group Collapses Upon Entering Inline Edit Mode

1 Answer 83 Views
Grid
This is a migrated thread and some comments may be shown as answers.
RYNETECH
Top achievements
Rank 1
RYNETECH asked on 03 Dec 2013, 03:30 PM
Greetings,

I'm using the following RadGrip markup.  By default the grid renders with all groups collapsed.  When I expand a group, I see all items, but if I edit an item, I lose the expansion of the group and only see the item that I'm editing.  Upon exiting edit mode, I am returned to a collapsed group, causing me to have to re-expand and search for the item that I was working with.  How can I cause the group to remain expanded upon editing and/or exiting edit mode?

            <telerik:RadGrid ID="rgProgramNotes" runat="server" AutoGenerateColumns="false" AllowSorting="true" ShowHeadersWhenNoRecords="true">
                <ClientSettings EnableRowHoverStyle="true" AllowGroupExpandCollapse="True" AllowDragToGroup="False" Selecting-AllowRowSelect="true">
                    <Scrolling  AllowScroll="false" UseStaticHeaders="true" />
                </ClientSettings>
                <MasterTableView TableLayout="Fixed" DataKeyNames="NoteId" GroupLoadMode="Client" GroupsDefaultExpanded="False">
                    <GroupByExpressions>
                      <telerik:GridGroupByExpression>
                        <SelectFields>
                          <telerik:GridGroupByField FieldName="ContactType" HeaderText=" " HeaderValueSeparator="" />
                        </SelectFields>
                        <GroupByFields>
                          <telerik:GridGroupByField FieldName="ContactType" />
                        </GroupByFields>
                      </telerik:GridGroupByExpression>
                    </GroupByExpressions>
                    <ItemStyle Wrap="false" />
                    <AlternatingItemStyle Wrap="false" />
                    <Columns>
                        <telerik:GridButtonColumn ButtonType="LinkButton" ButtonCssClass="k-icon k-edit" HeaderStyle-Width="25px" CommandName="Edit" />
                        <telerik:GridButtonColumn ButtonType="LinkButton" ButtonCssClass="k-icon k-delete" HeaderStyle-Width="25px" CommandName="Delete" ConfirmText="Are you sure you want to delete this Note?" />
                        <telerik:GridBoundColumn DataField="ContactCompany" HeaderText="Contact Company" SortExpression="ContactCompany" HeaderStyle-Width="175px" HeaderStyle-HorizontalAlign="Left" AllowFiltering="false" />
                        <telerik:GridBoundColumn DataField="Date" HeaderText="Date" SortExpression="Date" DataFormatString="{0:MM/dd/yyyy}" HeaderStyle-Width="75px" HeaderStyle-HorizontalAlign="Left" AllowFiltering="false" />
                        <telerik:GridTemplateColumn HeaderText="Description" DataField="Description" HeaderStyle-Width="425px">
                            <ItemTemplate>
                               <%-- <%# Utilties.StringHtmlTagsAndCss(Eval("Description"))%>--%>
                               <asp:Label ID="lblDescription" runat="server"><%# Eval("Description") %></asp:Label>
                               <telerik:RadToolTip ID="RadToolTip1" runat="server" TargetControlID="lblDescription" RelativeTo="Mouse" Position="BottomCenter" AutoCloseDelay="0" RenderInPageRoot="true">
                                   <%# Eval("Description") %>
                              </telerik:RadToolTip>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn DataField="ContactName" HeaderText="Contact" SortExpression="ContactName" HeaderStyle-Width="100px" HeaderStyle-HorizontalAlign="Left" AllowFiltering="false" />
                        <telerik:GridBoundColumn DataField="NoteType" HeaderText="Type" SortExpression="NoteType" HeaderStyle-Width="30px" HeaderStyle-HorizontalAlign="Left" AllowFiltering="false" />
                        <telerik:GridBoundColumn DataField="User" HeaderText="Who" SortExpression="User" HeaderStyle-Width="30px" HeaderStyle-HorizontalAlign="Left" AllowFiltering="false" />
                    </Columns>
                    <EditFormSettings EditFormType="WebUserControl" UserControlName="~/Legacy/Ui/NoteTemplate.ascx" />
                </MasterTableView>
            </telerik:RadGrid>

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Dec 2013, 12:25 PM
Hi ,

Please try the sample code snippet to prevent the rows from collapsing.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
    OnGroupsChanging="RadGrid1_GroupsChanging" OnItemCommand="RadGrid1_ItemCommand"
    AutoGenerateEditColumn="true" OnPreRender="RadGrid1_PreRender">
    <ClientSettings AllowDragToGroup="True">
    </ClientSettings>
    <MasterTableView GroupLoadMode="Server" GroupsDefaultExpanded="False" EditMode="InPlace">
        <GroupByExpressions>
            <telerik:GridGroupByExpression>
                <GroupByFields>
                    <telerik:GridGroupByField FieldName="Group" />
                </GroupByFields>
                <SelectFields>
                    <telerik:GridGroupByField FieldName="Group" />
                </SelectFields>
            </telerik:GridGroupByExpression>
        </GroupByExpressions>
    </MasterTableView>
    <ClientSettings EnableRowHoverStyle="true" AllowGroupExpandCollapse="True" AllowDragToGroup="False"
        Selecting-AllowRowSelect="true">
        <Scrolling AllowScroll="false" UseStaticHeaders="true" />
    </ClientSettings>
</telerik:RadGrid>

C#:
public Hashtable Groups
{
    get
    {
        if (ViewState["Groups"] == null)
        {
            Hashtable res = new Hashtable();
            ViewState["Groups"] = res;
            return res;
        }
        return (Hashtable)ViewState["Groups"];
    }
    set
    {
        ViewState["Groups"] = value;
    }
}
 
protected void Page_Load(object sender, EventArgs e)
{
    RadGrid1.DataBound += new EventHandler(RadGrid1_DataBound);
}
 
void RadGrid1_DataBound(object sender, EventArgs e)
{
    foreach (GridGroupHeaderItem item in RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader))
    {
        if (Groups.ContainsKey(item.DataCell.Text))
        {
            item.Expanded = (bool)Groups[item.DataCell.Text];
        }
    }
}
 
protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    DataTable tbl = new DataTable();
    DataColumn col = new DataColumn("ID");
    col.DataType = typeof(int);
    tbl.Columns.Add(col);
    col = new DataColumn("Name");
    col.DataType = typeof(string);
    tbl.Columns.Add(col);
    col = new DataColumn("Group");
    col.DataType = typeof(string);
    tbl.Columns.Add(col);
 
    int size = 15;
    int maxLen = size.ToString().Length;
    for (int i = 1; i <= size; i++)
    {
        tbl.Rows.Add(new object[] { i, "Name" + i.ToString("D" + maxLen), "Group" + i % 5 });
    }
    RadGrid1.DataSource = tbl;
}
protected void RadGrid1_GroupsChanging(object source, GridGroupsChangingEventArgs e)
{
    Groups.Clear();
    foreach (GridGroupHeaderItem item in RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader))
    {
        Groups[item.DataCell.Text] = item.Expanded;
    }
}
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.ExpandCollapseCommandName)
    {
        Groups[((GridGroupHeaderItem)e.Item).DataCell.Text] = !e.Item.Expanded;
    }
    if (e.CommandName == RadGrid.EditCommandName && RadGrid1.MasterTableView.GroupByExpressions.Count > 0)
        group = e.Item.GroupIndex.Substring(0, e.Item.GroupIndex.LastIndexOf("_"));
}
    
string group = string.Empty;
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    if (!string.IsNullOrEmpty(group))
    {
        GridItem[] items = RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader);
        foreach (GridGroupHeaderItem item in items)
            if (item.GroupIndex == group)
                item.Expanded = true;
    }
}

Thanks,
Princy
Tags
Grid
Asked by
RYNETECH
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or