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

IgnorePaging exports everything in RadGrid

2 Answers 318 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Florent
Top achievements
Rank 1
Florent asked on 11 Aug 2016, 08:23 AM

Hello,

I've been trying to solve the problem by myself for a while now, but in vain.

I have a RadGrid, in which I have a GridClientSelectColumn. I've written JS functions so that selection is saved in a HiddenField even if you navigate through the pages of the grid. The thing is, when I try to export as an Excel file, it doesn't work. I mean that, without adding "IgnorePaging = true", the currently selected rows only are exported. But if I add this property, I would expect that every "selected row" (I mean every row saved in the HiddenField) get exported. Instead, I just get a file with ALL the rows, no matter if they were selected or not. I've been checking the HiddenField content, and it is filled as expected, so I don't know where the problem could come from.

 

Here is the Excel export function : 

public void ExportExcel(RadGrid radGrid)
        {
  // If ignore paging is true, export all data even if not in HiddenField "memory"
            radGrid.ExportSettings.IgnorePaging = true;
            radGrid.ExportSettings.ExportOnlyData = true;
            radGrid.ExportSettings.OpenInNewWindow = true;
            radGrid.MasterTableView.GetColumn("SelectColumn").Visible = false;
  // From here we want to select only registered lines. Work if ignore paging is false
            int count = 0;
            foreach (GridDataItem dataItem in radGrid.MasterTableView.Items)
            {
                if(HiddenField1.Value.IndexOf("," + count + ",") < 0) {
                    dataItem.Visible = false;
                }
                count++;
            }
            radGrid.MasterTableView.ExportToExcel();
        }

Selected rows are "saved" in the hidden field with JS like this : 

function AddorRemoveIdInHiddenField(hf, id, IsAdd) {
 
                if (document.getElementById(hf).value == "") {
                    document.getElementById(hf).value = ",";
                }
 
                if (IsAdd == true) {
                    if (document.getElementById(hf).value.indexOf("," + id + ",") == -1) {
                        document.getElementById(hf).value = document.getElementById(hf).value + id + ",";
                    }
                }
                else if (IsAdd == false) {
                    if (document.getElementById(hf).value.indexOf("," + id + ",") >= 0) {
                      document.getElementById(hf).value = document.getElementById(hf).value.replace("," + id + ",", ",");
                    }
                }
            }

Here is my RadGrid code : 

<telerik:RadGrid ID="rgAgents" runat="server" RenderMode="Lightweight" Culture="fr-FR" OnNeedDataSource="rgAgents_NeedDataSource" AutoGenerateColumns="false" AllowPaging="True" AllowMultiRowSelection="true" OnItemCreated="rgAgents_ItemCreated" AllowSorting="True" GridLines="None" PageSize="15" MasterTableView-ExpandCollapseColumn-Display="false" AllowFilteringByColumn="true">
 <PagerStyle Mode="Slider" Position="Bottom" PageSizeControlType="None"></PagerStyle>
 <GroupingSettings CaseSensitive="false" />
 <MasterTableView AutoGenerateColumns="false" TableLayout="Fixed" DataKeyNames="ID" ClientDataKeyNames="ID">
  <NestedViewTemplate></NestedViewTemplate>
     <columns>
       <telerik:GridClientSelectColumn UniqueName="SelectColumn"></telerik:GridClientSelectColumn>
        <telerik:GridBoundColumn DataField="ID" HeaderText="ID" Visible="false">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Nom" HeaderText="Nom">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Prénom" HeaderText="Prénom">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Matricule" HeaderText="Matricule">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Groupe" HeaderText="Groupe">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Service" HeaderText="Service">
        </telerik:GridBoundColumn>
        <telerik:GridDateTimeColumn DataField="Mail" HeaderText="Mail" AllowFiltering="false">
        </telerik:GridDateTimeColumn>
        <telerik:GridBoundColumn DataField="Téléphone" HeaderText="Téléphone" AllowFiltering="false">
        </telerik:GridBoundColumn>
    </columns>
   </MasterTableView>
   <ClientSettings>
   <Selecting AllowRowSelect="true" EnableDragToSelectRows="true" />
   <ClientEvents OnRowCreated="rgAgents_RowCreated" OnRowSelected="rgAgents_RowSelected"
            OnRowDeselected="rgAgents_RowDeselected" OnGridCreated="GridCreated" />
   </ClientSettings>
   </telerik:RadGrid>
   <asp:HiddenField ID="HiddenField1" runat="server" Value="" ClientIDMode="Static" />

2 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 16 Aug 2016, 06:02 AM
Hello Florent,

When using IgnorePaging option while exporting, the grid rebinds its records internally before the actual export operation in order to get the entire collection of rows. You can try using your custom logic during the ItemDataBound even handler:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem && RadGrid1.IsExporting)
    {
        if (true) // custom condition logic
        {
            e.Item.Visible = false;
            e.Item.Display = false; // alternative approach
        }
    }
}

In addition, you can also examine the RadGridGetAllSelectedItemsImproved.zip sample provided in the following post for a similar selection preserving logic:
http://www.telerik.com/support/code-library/get-selected-items-through-all-pages#1eTU8nr-GUG8zfGgOGbIcA


I hope this will prove helpful.

Regards,
Eyup
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Florent
Top achievements
Rank 1
answered on 16 Aug 2016, 07:23 AM

Hello Eyup, 

your help has been really helpful and solved my problem.

Thanks a lot.

Tags
General Discussions
Asked by
Florent
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Florent
Top achievements
Rank 1
Share this question
or