Radgrid custom paging with export to excel

11 posts, 0 answers
  1. Gajanan
    Gajanan  avatar
    49 posts
    Member since:
    May 2010

    Posted 29 Jul 2013 Link to this post

    Hi All,

    I have Radgrid for which i am using custom paging,and i need to give export to excel functionality for this Grid, and i am using RadGrid the Export to excel functionality, but it is not working some times , some times means 
    when the page load without giving any filter to grid this export to excel functionality is working , but when i give any column filter that time it is not working properly , even my grid is showing 100 records with 10 pages but when i click export button it is exporting only first page records (my Radgrid page size is 10 records per page.), even though i given IgnorePaging = True in Export setting.
    but when i tried for the RadGrid where custom paging is not implimented for that RadGrid it is working

    if You have any solution regarding this please help me to sharing.

    My code is below
    <telerik:RadGrid ID="rg_PlannedOrders" runat="server" OnNeedDataSource="rg_PlannedOrders_NeedDataSource" AllowMultiRowSelection="true"
                             AllowCustomPaging="true" OnDeleteCommand="rg_PlannedOrders_DeleteCommand" OnItemDataBound="rg_PlannedOrders_OnItemDataBound"
                             OnItemCommand="rg_PlannedOrders_ItemCommand" OnPageIndexChanged="rg_PlannedOrders_PageIndexChanged" PageSize="50" >
                               <ExportSettings ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true" HideStructureColumns="false"  FileName = "PlannedOrderExc">
                                    <Excel Format="Biff" />
                       </ExportSettings> 
                            <MasterTableView CommandItemDisplay="Top" AllowMultiColumnSorting="true" AutoGenerateColumns="false">

       
    CS side code is 

    protected void rg_PlannedOrders_ItemCommand(object sender, GridCommandEventArgs e)
         {
             try
             {
                 switch (e.CommandName)
                 {
     case RadGrid.ExportToExcelCommandName:
                         rg_PlannedOrders.AllowCustomPaging = false;
                         ((GridColumn)rg_PlannedOrders.Columns.FindByUniqueName("DeleteCommandColumn")).Visible = false;
                         ((GridColumn)rg_PlannedOrders.Columns.FindByUniqueName("CheckBoxSelect_Detail")).Visible = false;
                         ((GridColumn)rg_PlannedOrders.Columns.FindByUniqueName("History")).Visible = false;
                         ((GridColumn)rg_PlannedOrders.Columns.FindByUniqueName("TemplateColumn_IsConsolidate")).Visible = false;
                         ((GridColumn)rg_PlannedOrders.Columns.FindByUniqueName("Temp_IsContractMRP")).Visible = false;

                         break;


                     default:

                         break;

                            
    }
                 string RgInvantoryCache = GetSearchCacheName();
                 GridSettingsPersister.SaveGridSettings(rg_PlannedOrders, e, RgInvantoryCache);

             }
             catch (Exception oException)
             {  }

    Thanks 
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 29 Jul 2013 Link to this post

    Hi Gajanan,

    When you have custom paging enabled for your grid, you need to set the PageSize property of the grid to be equal to the VirtualItemCount in order to export all records successfully with IgnorePaging set to true.Edit your Code as:

    ASPX:
    <telerik:RadGrid ID="RadGrid1" ShowGroupPanel="true"
        runat="server" AllowPaging="True"  AllowCustomPaging="True" VirtualItemCount="10000"   OnNeedDataSource="RadGrid1_NeedDataSource"  OnItemCommand="RadGrid1_ItemCommand" >
        <ExportSettings Excel-Format="Biff"></ExportSettings>
        <MasterTableView CommandItemDisplay="Top">
            <CommandItemSettings ShowExportToExcelButton="true" />
        </MasterTableView>
    </telerik:RadGrid>

    C#:
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
          {
              try
              {
                  switch (e.CommandName)
                  {
                      case RadGrid.ExportToExcelCommandName:
                          RadGrid1.PageSize = RadGrid1.MasterTableView.VirtualItemCount;
                          RadGrid1.ExportSettings.ExportOnlyData = true;
                          RadGrid1.ExportSettings.IgnorePaging = true;
                          RadGrid1.ExportSettings.OpenInNewWindow = true;                     
                         // Your Codes
                          RadGrid1.MasterTableView.ExportToExcel();
                          break;
                      default: break;
                  }
              }
              catch (Exception oException)
              { }
          }

    The exporting feature works only with regular postbacks. This means, that the asynchronous postback should be canceled when performing an export.See the below code.

    ASPX:
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <ClientEvents OnRequestStart="onRequestStart"></ClientEvents>
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGrid1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
    </telerik:RadAjaxManager>

    JS:
    <script type="text/javascript">
        function onRequestStart(sender, args) {
            if (args.get_eventTarget().indexOf("ExportTo") >= 0) {
                args.set_enableAjax(false);
            }
        }
    </script>


    Hope this helps,
    Thanks,
    Princy

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Gajanan
    Gajanan  avatar
    49 posts
    Member since:
    May 2010

    Posted 30 Jul 2013 Link to this post

    hi Princy

    thanks for quick replay . in my radgrid i mentioned VirtualItemCount="64000" and i added the the below code in Radgrid command event
     rg_PlannedOrders.PageSize = rg_PlannedOrders.MasterTableView.VirtualItemCount;
                         rg_PlannedOrders.ExportSettings.ExportOnlyData = true;
                         rg_PlannedOrders.ExportSettings.IgnorePaging = true;
                         rg_PlannedOrders.ExportSettings.OpenInNewWindow = true;  
                         
                         ((GridColumn)rg_PlannedOrders.Columns.FindByUniqueName("DeleteCommandColumn")).Visible = false;
                         ((GridColumn)rg_PlannedOrders.Columns.FindByUniqueName("CheckBoxSelect_Detail")).Visible = false;
                         ((GridColumn)rg_PlannedOrders.Columns.FindByUniqueName("History")).Visible = false;
                         ((GridColumn)rg_PlannedOrders.Columns.FindByUniqueName("TemplateColumn_IsConsolidate")).Visible = false;
                         ((GridColumn)rg_PlannedOrders.Columns.FindByUniqueName("Temp_IsContractMRP")).Visible = false;
                         rg_PlannedOrders.MasterTableView.ExportToExcel();


    but still it is exporting only first page records in excel


    thanks
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 30 Jul 2013 Link to this post

    Hi Gajanan,

    I see that you are hiding some column during Export.Can you please try the below code snippet and see if it helps.

    C#:
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        try
        {
            switch (e.CommandName)
            {
                case RadGrid.ExportToExcelCommandName:
                             
                    RadGrid1.PageSize = RadGrid1.MasterTableView.VirtualItemCount;
                    RadGrid1.ExportSettings.ExportOnlyData = true;
                    RadGrid1.ExportSettings.IgnorePaging = true;
                    RadGrid1.ExportSettings.OpenInNewWindow = true;
                    RadGrid1.MasterTableView.GetColumn("UniqueColumnName").Visible = false;//Hide Column During Export
                    RadGrid1.MasterTableView.ExportToExcel();
                    break;
                default: break;
            }
        }
        catch (Exception oException)
        { }
    }


    Thanks,
    Princy
  6. Gajanan
    Gajanan  avatar
    49 posts
    Member since:
    May 2010

    Posted 01 Aug 2013 Link to this post

    hi princy,

    thank you for replay
    i used the code 
    RadGrid1.MasterTableView.GetColumn("UniqueColumnName").Visible = false;
     to Hide columns while exporting

    now the export to excel is working fine , but the problem is even i used above code to hide columns then also it is appearing in Excel
    actually above code is not working even i tried for my old code that also not working,

    i have a delete and Edit column in my Radgrid and i don't want this column while exporting to excel.


    please help
    Thanks


  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 01 Aug 2013 Link to this post

    Hi ,

    I tried to replicate the issue but no avail.When you set ExportOnlyData=true, it will exclude edit-command column,button-columns etc during export.Here is the code that i tried,i have attached the screenshot too.The Unit Price column is hidden during export.
    To hide a column we use RadGrid1.MasterTableView.GetColumn("UniqueColumnName").Visible = false;

    ASPX:
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
             <ClientEvents OnRequestStart="onRequestStart"></ClientEvents>
             <AjaxSettings>
                 <telerik:AjaxSetting AjaxControlID="RadGrid1">
                     <UpdatedControls>
                         <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                     </UpdatedControls>
                 </telerik:AjaxSetting>
             </AjaxSettings>
         </telerik:RadAjaxManager>
         <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" ToolTip="" runat="server">
         </telerik:RadAjaxLoadingPanel>
         <telerik:RadGrid ID="RadGrid1"  runat="server" AllowPaging="True" AllowSorting="true"
             AllowCustomPaging="True" VirtualItemCount="10000" OnNeedDataSource="RadGrid1_NeedDataSource"           
             OnItemCommand="RadGrid1_ItemCommand" >
             <ExportSettings Excel-Format="Biff">
             </ExportSettings>
             <MasterTableView CommandItemDisplay="Top">
                 <CommandItemSettings ShowExportToExcelButton="true" />
                 <Columns>
                     <telerik:GridEditCommandColumn UniqueName="editrow">
                     </telerik:GridEditCommandColumn>
                     <telerik:GridButtonColumn UniqueName="deleterow" CommandName="Delete" Text="Delete"
                         ButtonType="LinkButton">
                     </telerik:GridButtonColumn>
                 </Columns>
             </MasterTableView>
         </telerik:RadGrid>

    C#:
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        try
        {
            switch (e.CommandName)
            {
                case RadGrid.ExportToExcelCommandName:
                            
                    RadGrid1.PageSize = RadGrid1.MasterTableView.VirtualItemCount;
                    RadGrid1.ExportSettings.ExportOnlyData = true;
                    RadGrid1.ExportSettings.IgnorePaging = true;
                    RadGrid1.ExportSettings.OpenInNewWindow = true;
                    RadGrid1.MasterTableView.GetColumn("UnitPrice").Visible = false;    //To hide a column
                    RadGrid1.MasterTableView.ExportToExcel();
                    break;
                default: break;
            }
        }
        catch (Exception oException)
        { }
    }

    JS:
    <script type="text/javascript">
        function onRequestStart(sender, args) {
            if (args.get_eventTarget().indexOf("ExportTo") >= 0) {
                args.set_enableAjax(false);
            }
        }
    </script>
  8. Hardik
    Hardik avatar
    6 posts
    Member since:
    Dec 2013

    Posted 09 Dec 2014 Link to this post

    After doing this all things Export to Excel is working but immediate after that navigate to next page Navigation panel disappears.
  9. Angel Petrov
    Admin
    Angel Petrov avatar
    1007 posts

    Posted 12 Dec 2014 Link to this post

    Hello Hardik,

    Could you please share with us the problematic page contents so we could examine the code? If you can provide us with a sample in which this problem can be observed that would be great.

    Regards,
    Angel Petrov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  10. Hardik
    Hardik avatar
    6 posts
    Member since:
    Dec 2013

    Posted 18 Dec 2014 in reply to Angel Petrov Link to this post

    Hi,
    I got the resolution. It was happening because of below code,
    //protected override void SavePageStateToPersistenceMedium(object viewState)
    //{
    // Session["ViewState" + this.Page.ToString()] = viewState;
    //}
    //protected override object LoadPageStateFromPersistenceMedium()
    //{
            // return Session["ViewState" + this.Page.ToString()];
    //}
    But yes there is a bug in custom paging to avoid that bug we needs to set page index to 0 on ItemCommand event to get proper out put when we are on other page index than 0.
    Thanks,
    Hardik Vadher
  11. Hardik
    Hardik avatar
    6 posts
    Member since:
    Dec 2013

    Posted 18 Dec 2014 in reply to Hardik Link to this post

    gvOpenAR.CurrentPageIndex = 0;
    gvOpenAR.PageSize = gvOpenAR.MasterTableView.VirtualItemCount;
    gvOpenAR.ExportSettings.ExportOnlyData = true;
    gvOpenAR.ExportSettings.IgnorePaging = true;
    gvOpenAR.ExportSettings.OpenInNewWindow = true;
    gvOpenAR.MasterTableView.ExportToExcel();
  12. Angel Petrov
    Admin
    Angel Petrov avatar
    1007 posts

    Posted 23 Dec 2014 Link to this post

    Hello Hardik,

    In order to research whether there is a problem on our end we would need the markup and code-behind of the page. That said could you please send them for review?

    Regards,
    Angel Petrov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017