I have a radgrid that may, at times, hold up to or over 30,000 rows. We also have custom paging in place on this radgrid. I've read several places that the radgrid is not meant to handle exporting such large amounts of data. I'm totally fine with this but, from a user point of view, I need a way to cancel such requests and display a message to the user. I'd like to either:
A) Set the exporting buttons on the radgrid to disabled but still show them when the records are over a certain amount.
Or
B) Stop the exporting event on the item command (or at any other point?) when records are over a certain amount and display a message to the user (this one is more favorable).
I have found that I can cancel the exporting by reacting to the client side event of the item command but the moment I add the client side event, even though it does absolutely nothing, the exporting no longer works. The application fires the item command event in the code behind and on the client side but never reaches the grid exporting event. It also never exports. Instead it merely returns the radgrid with the new page size and the removed filters and headers.
Any advice or examples on how to achieve either of these outcomes would be greatly appreciated.
A) Set the exporting buttons on the radgrid to disabled but still show them when the records are over a certain amount.
Or
B) Stop the exporting event on the item command (or at any other point?) when records are over a certain amount and display a message to the user (this one is more favorable).
I have found that I can cancel the exporting by reacting to the client side event of the item command but the moment I add the client side event, even though it does absolutely nothing, the exporting no longer works. The application fires the item command event in the code behind and on the client side but never reaches the grid exporting event. It also never exports. Instead it merely returns the radgrid with the new page size and the removed filters and headers.
protected void RadGridInventory_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.ExportToExcelCommandName || e.CommandName == RadGrid.ExportToCsvCommandName)
{
RadGridInventory.PageSize = RadGridInventory.MasterTableView.VirtualItemCount;
}
if (e.CommandName == RadGrid.ExportToExcelCommandName)
{
var headerItem = (GridHeaderItem)RadGridInventory.MasterTableView.GetItems(GridItemType.Header)[0];
headerItem.Visible = true;
isExport = true;
}
if (e.CommandName == RadGrid.ExportToCsvCommandName)
{
RadGridInventory.MasterTableView.GetColumn("CSVAcountId").Display = true;
RadGridInventory.MasterTableView.GetColumn("AccountId").Display = false;
RadGridInventory.MasterTableView.GetColumn("CSVStatus").Display = true;
RadGridInventory.MasterTableView.GetColumn("Status").Display = false;
}
}
protected void RadGridInventory_GridExporting(object source, GridExportingArgs e)
{
if (e.ExportType == ExportType.Excel)
{
string customText = "<
h1
style
=
'text-align:center;'
>Inventory Report for " + _applicationUser.Customer.Name + "</
h1
>";
customText += "<
p
style
=
'text-align:center;'
><
b
>Current Date:</
b
> " + DateTime.Now + "<
br
/>";
if(RadDatePickerStarting.SelectedDate != null && RadDatePickerEnding.SelectedDate != null){
customText += "<
b
>Date Range Covered:</
b
> " + RadDatePickerStarting.SelectedDate + " - " + RadDatePickerEnding.SelectedDate + "<
br
/>";
} else {
customText += "<
b
>Date Range Covered:</
b
> " + RadComboBoxChoices.SelectedItem.Text + "<
br
/>";
}
customText += "<
b
>Clients:</
b
>";
foreach (var client in ClientSelector1.SelectedClients)
{
customText += " " + client.Name + ",";
}
customText = customText.TrimEnd(',');
customText += "</
p
>";
e.ExportOutput = e.ExportOutput.Replace("<
body
>", "<
body
>" + customText);
}
isExport = false;
}
<
script
type
=
"text/javascript"
>
function onRequestStart(sender, args) {
if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0 ||
args.get_eventTarget().indexOf("ExportToCsvButton") >= 0) {
args.set_enableAjax(false);
}
}
function onCommand(sender, args) {
}
</
script
>
Any advice or examples on how to achieve either of these outcomes would be greatly appreciated.