0
When I export Radgrid from Telerik to Excel, when Radgrid has many records, it loses paging. I tried to solve with rebind, but it didn’t work. Would anyone have any idea?
Attached the screens before and after export to excel. After exporting to excel and clicking on one of the Paggings. The Paggings vanish.
Before trying the solution with rivend, it was more frequent this occur, now it occurs more often, sometimes it does not occur. Also, when I click on the other tabs, which also contain grids with records, when I export to excel, and give the rebind, it goes back to the main tab.
I would also like to know how to keep myself in the same tab where I exported the records to excel. When I am in the main tab, the other tabs are active only when I select a line, so they load with the line information. However, after the rebind, this information from the other tabs is lost.
Code in C#:
private void ClickToolbar(short value)
{
this.ExportSettings.HideStructureColumns = true;
this.ExportSettings.FileName = string.Concat(this.ExportSettings.Pdf.PageTitle, " - Exportação");
this.MasterTableView.HierarchyDefaultExpanded = false;
this.MasterTableView.HierarchyLoadMode = GridChildLoadMode.ServerOnDemand;
if (this.MasterTableView.HasDetailTables)
{
for (int i = 0; i < this.MasterTableView.DetailTables.Count; i++)
{
this.MasterTableView.DetailTables[i].HierarchyDefaultExpanded = false;
this.MasterTableView.DetailTables[i].HierarchyLoadMode = GridChildLoadMode.ServerOnDemand;
}
}
GridTableView backupMasterTableView = this.MasterTableView.Clone();
switch (value)
{
case 0:
GridSettingsPersister savePersister = new GridSettingsPersister(this);
object[] parameters = new object[] { this.IdGridConfiguracao, savePersister.SaveSettings() };
this.Page.GetType().GetMethod("SalvarConfiguracaoGrid").Invoke(this.Page, parameters);
if (RebindOnClickSaveToolbar)
this.Rebind();
break;
case 2:
exporting = true;
PrepareToPrintGrid();
this.MasterTableView.ExportToPdf();
break;
case 4:
#region Formato do Excel
this.ExportSettings.Excel.Format = Telerik.Web.UI.GridExcelExportFormat.Biff;
#endregion
PrepareToPrintGrid();
exporting = true;
this.MasterTableView.ExportToExcel();
this.MasterTableView.Rebind();
break;
}
if (exporting)
{
this.MasterTableView.HeaderStyle.Wrap = backupMasterTableView.HeaderStyle.Wrap;
this.MasterTableView.ItemStyle.Wrap = backupMasterTableView.ItemStyle.Wrap;
this.MasterTableView.Font.Size = backupMasterTableView.Font.Size;
this.MasterTableView.Font.Name = backupMasterTableView.Font.Name;
this.MasterTableView.Style["vertical-align"] = backupMasterTableView.Style["vertical-align"];
this.MasterTableView.Style["text-align"] = backupMasterTableView.Style["text-align"];
this.MasterTableView.UseAllDataFields = backupMasterTableView.UseAllDataFields;
this.MasterTableView.HierarchyDefaultExpanded = backupMasterTableView.HierarchyDefaultExpanded;
this.MasterTableView.HierarchyLoadMode = backupMasterTableView.HierarchyLoadMode;
this.MasterTableView.PageSize = backupMasterTableView.PageSize;
this.MasterTableView.AllowPaging = backupMasterTableView.AllowPaging;
}
}
protected void PrepareToPrintGrid()
{
#region Seleciona o tamanho do papel
// Change to legal paper for high column counts
if (this.MasterTableView.Columns.Count > 8)
{
this.ExportSettings.Pdf.PaperSize = GridPaperSize.Legal;
}
// Change to portrait if many columns
if (this.MasterTableView.Columns.Count > 3)
{
Unit swapUnit = this.ExportSettings.Pdf.PageWidth;
this.ExportSettings.Pdf.PageWidth = this.ExportSettings.Pdf.PageHeight;
this.ExportSettings.Pdf.PageHeight = swapUnit;
this.ExportSettings.IgnorePaging = true;
this.ExportSettings.OpenInNewWindow = true;
}
#endregion
#region Estilos
this.ExportSettings.Pdf.DefaultFontFamily = "Segoe UI";
this.MasterTableView.HeaderStyle.Wrap = true;
this.MasterTableView.ItemStyle.Wrap = true;
this.MasterTableView.Font.Size = 8;
this.MasterTableView.Font.Name = "Segoe UI";
this.MasterTableView.Style["vertical-align"] = "middle";
this.MasterTableView.Style["text-align"] = "left";
#endregion
//this.ExportSettings.IgnorePaging = true;
this.ExportSettings.IgnorePaging = true;
this.ExportSettings.OpenInNewWindow = true;
this.MasterTableView.UseAllDataFields = true;
#region Expande Detailstable
this.MasterTableView.HierarchyDefaultExpanded = true;
this.MasterTableView.HierarchyLoadMode = GridChildLoadMode.Client;
if (this.MasterTableView.HasDetailTables)
{
for (int i = 0; i < this.MasterTableView.DetailTables.Count; i++)
{
this.MasterTableView.DetailTables[i].HierarchyLoadMode = GridChildLoadMode.Client;
this.MasterTableView.DetailTables[i].HierarchyDefaultExpanded = true;
}
this.MasterTableView.HierarchyDefaultExpanded = true;
}
#endregion
}
Javascript code:
$(document).on('click', '.btn_toolbar_excel', function (e) {
setTimeout(function () { preventTableBreakPager() }, 5000);
})
function preventTableBreakPager()
{
var gridVeiculosList = $find(gridVeiculos).get_masterTableView();
gridVeiculosList.rebind();
}
I don’t get it... Aren’t you filling out all the information for Excel when there are too many records? Or do you expect Excel to implement paging? Present the code...
– Leandro Angelo
It saves right. Only, grid paging is lost. When I click on the export button, I can save all the information. But after this procedure, when I click on one of the patterns, the grid is lost, there is only one pagination. I made several changes, before it was a long pagination with all the records, now only one with few records. I will post two prints before and after exporting to excel.
– Bianca Nunes
And the code of the method you export, where it is?
– Leandro Angelo
I posted up there.
– Bianca Nunes