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"
/>