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

Refresh grid and groups

1 Answer 49 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stefania
Top achievements
Rank 2
Stefania asked on 12 Dec 2013, 09:52 AM
Hi,
I'm trying to refresh my grid and groups

<telerik:RadGrid ID="HomeRadGrid" runat="server" OnNeedDataSource="HomeRadGrid_NeedDataSource"
          EnableEmbeddedSkins="False" AllowPaging="True" AllowAutomaticUpdates="false"
          AllowAutomaticInserts="false" AllowAutomaticDeletes="false" AllowSorting="True"
          AllowFilteringByColumn="True" CellSpacing="0" Culture="it-IT" GridLines="None"
          OnItemCommand = "HomeRadGrid_ItemCommand" OnGroupsChanging="HomeRadGrid_GroupsChanging"
          OnItemDataBound = "HomeRadGrid_ItemDataBound"
          Skin="MySkin" ShowGroupPanel="True">
          <PagerStyle Mode="NextPrevAndNumeric" />
          <MasterTableView AutoGenerateColumns="False"  CommandItemDisplay="Top" DataKeyNames="Id">
           <ColumnGroups>
                      <telerik:GridColumnGroup Name="GeneralInformation" HeaderText="General Information"
                          HeaderStyle-HorizontalAlign="Center" />
                      <telerik:GridColumnGroup Name="WarningsIcon" HeaderText="Warnings"
                          HeaderStyle-HorizontalAlign="Center" />
                  </ColumnGroups>
          <CommandItemSettings RefreshText="" ShowAddNewRecordButton="false" />          
              <GroupByExpressions>
                  <telerik:GridGroupByExpression>
                      <SelectFields>
                          <telerik:GridGroupByField FieldAlias="Company" FieldName="Cdc.CompanyCode"></telerik:GridGroupByField>
                      </SelectFields>
                      <GroupByFields>
                          <telerik:GridGroupByField FieldName="Cdc.CompanyCode" SortOrder="Descending"></telerik:GridGroupByField>
                      </GroupByFields>
                  </telerik:GridGroupByExpression>
                  <telerik:GridGroupByExpression>
                      <SelectFields>
                          <telerik:GridGroupByField FieldAlias="Project" FieldName="Cdc.Code" ></telerik:GridGroupByField>
                      </SelectFields>
                      <GroupByFields>
                          <telerik:GridGroupByField FieldName="Cdc.Code"></telerik:GridGroupByField>
                      </GroupByFields>
                  </telerik:GridGroupByExpression>
              </GroupByExpressions>
              <Columns>
                  <telerik:GridBoundColumn DataField="Cdc.CompanyCode" HeaderText="Company Code" SortExpression="Cdc.CompanyCode"
                      UniqueName="Cdc.CompanyCode" Visible="false" ColumnGroupName="GeneralInformation" >
                  </telerik:GridBoundColumn>
                  <telerik:GridBoundColumn DataField="Cdc.Code" HeaderText="Project" SortExpression="Cdc.Code"
                      UniqueName="Cdc.Code" Visible="false" ColumnGroupName="GeneralInformation" >
                  </telerik:GridBoundColumn>
                   
                  ...
              </Columns>
                <NestedViewTemplate>
                      ...
                  </NestedViewTemplate>
          </MasterTableView>
          <ClientSettings ReorderColumnsOnClient="True" AllowDragToGroup="True" AllowColumnsReorder="True">
          <ClientEvents OnRowDblClick="RowDblClick"></ClientEvents>
              <Selecting AllowRowSelect="False"></Selecting>
              <Resizing AllowRowResize="True" AllowColumnResize="True" EnableRealTimeResize="True"
                  ResizeGridOnColumnResize="False"></Resizing>
          </ClientSettings>
          <GroupingSettings ShowUnGroupButton="true"></GroupingSettings>
      </telerik:RadGrid>
C#

/// <summary>
       /// Eventi sul grid
       /// </summary>
       /// <param name="sender"></param>
       /// <param name="e"></param>
       protected void HomeRadGrid_ItemCommand(object sender, GridCommandEventArgs e)
       {
           switch (e.CommandName)
           {
               case "RebindGrid":
 
                   //tolgo i filtri
                   foreach (GridColumn column in HomeRadGrid.MasterTableView.OwnerGrid.Columns)
                   {
                       column.CurrentFilterFunction = GridKnownFunction.NoFilter;
                       column.CurrentFilterValue = string.Empty;                       
                   }
                   HomeRadGrid.MasterTableView.FilterExpression = string.Empty;
 
                   //tolgo i gruppi
                   HomeRadGrid.MasterTableView.GroupByExpressions.Clear();
                   //Refresh datagrid               
                   HomeRadGrid.Rebind();
                   break;
 
             
       }

1 Answer, 1 is accepted

Sort by
0
Deyan Enchev
Telerik team
answered on 17 Dec 2013, 09:37 AM
Hi Stefania,

Thank you for contacting Telerik support and sharing you code.

It seems that the logic you were executing on ItemCommand could be optimized for achieving the desired result. Could you review the attached sample project I have created, based on your code, and verify does it meet your requirements? I have also recorded a video showing my actions, in case I am missing something let me know.

In addition please note that when executing server logic within the RadGrid using ItemCommand handler the initiator should be a command coming from the RadGrid itself. In this scenario this would be the Refresh button, part of the default set that our RadGrid’s command item feature has.

Looking forward to your reply.


Regards,
Deyan Enchev
Telerik
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 the blog feed now.
Tags
Grid
Asked by
Stefania
Top achievements
Rank 2
Answers by
Deyan Enchev
Telerik team
Share this question
or