AUTHOR: Peter Milchev
DATE POSTED: July 04, 2018
Loading a large amount of data in the Spreadsheet might result in a slow page loading.
The issue is caused by the rendering of the control itself and not the data. This can be confirmed by adding a breakpoint in the PageInit, PagePreRenderComplete and PageUnload events and the most of the processing time would be between PagePreRenderComplete and PageUnload.
The solution is to save the data in JSON, pass it to the client and use the .fromJSON method of the underlying Kendo UI Spreadsheet. The following example with around 800,000 cells would be loaded for a few seconds while if the same amount of cells were loaded via a Provider or added directly to the Spreadsheet, the time would be a few minutes.
<
asp:HiddenField
runat
=
"server"
ID
"HiddenField1"
/>
telerik:RadSpreadsheet
"RadSpreadsheet1"
></
>
<script>
function
pageLoadHandler() {
var
spreadsheet = $find(
"<%= RadSpreadsheet1.ClientID %>"
);
value = $get(
"<%= HiddenField1.ClientID %>"
).value;
valueAsJSON = JSON.parse(value);
spreadsheet.get_kendoWidget().fromJSON(valueAsJSON);
}
Sys.Application.add_load(pageLoadHandler);
</script>
protected
void
Page_Init(
object
sender, EventArgs e)
{
var workbook =
new
Telerik.Web.Spreadsheet.Workbook();
PopulateSheet(workbook.AddSheet(),
"Workbook 1"
, 1598, 94);
"Workbook 2"
, 19627, 28);
"Workbook 3"
, 13325, 10);
"Workbook 4"
, 170, 26);
"Workbook 5"
, 44, 40);
"Workbook 6"
, 312, 23);
"Workbook 7"
, 297, 9);
var json = workbook.ToJson();
HiddenField1.Value = json;
private
static
PopulateSheet(Worksheet sheet,
string
sheetName,
int
rowsCount,
columnsCount)
sheet.Name = sheetName;
sheet.Columns =
List<Column>();
var row =
Row() { Index = 0 };
// columns
columnIndex = 0;
for
(
i = 0; i < columnsCount; i++)
sheet.Columns.Add(
Column());
cellValue =
"header"
+ i;
var cell =
Cell() { Index = columnIndex++, Value = cellValue, Background =
"#bfbfbf"
, Bold =
true
};
row.AddCell(cell);
sheet.AddRow(row);
// rows
rowIndex = 1;
r = 0; r < rowsCount; r++)
row =
Row() { Index = rowIndex++ };
c = 0; c < columnsCount; c++)
"Row"
+ r +
"; Col:"
+ c;
Cell() { Index = columnIndex++, Value = cellValue };
Resources Buy Try