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

Built-in Export Button disappears

1 Answer 48 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 05 Apr 2019, 08:02 PM

I have an programmatically built Ajaxified RadGrid that is being built when the RadToolTipManager is called and TheRadToolTipManager_AjaxUpdate event is triggered. The tool tip and grid works and shows all the data I am looking for, and I would like to be able to export the data. I am using the built-in export button that the RadGrid has available, but when I click the export button it disappears and no export file is created. I have read the Export from Ajaxified Grid page and understand that the built-in button already performs the post backs, so I am stuck. 

 

Programmatically built RadGrid:

private void UpdateToolTip(string elementID, UpdatePanel panel)
{
      RadGrid toolTipGrid= new RadGrid();
      toolTipGrid.ID = "ToolTipGridID";
      toolTipGrid.AutoGenerateColumns = false;
      toolTipGrid.EnableViewState = false;
      toolTipGrid.MasterTableView.ExpandCollapseColumn.Visible = false;
                 
      GridBoundColumn boundColumn = new GridBoundColumn();
      boundColumn.DataField = "Data1";
      boundColumn.HeaderText = "Data1";
      boundColumn.DataType = typeof(string);
      boundColumn.UniqueName = "Data1";
      boundColumn.Exportable = true;
      toolTipGrid.MasterTableView.Columns.Add(boundColumn);
 
      boundColumn = new GridBoundColumn();
      boundColumn.DataField = "Data2";
      boundColumn.HeaderText = "Data2";
      boundColumn.DataType = typeof(int);
      boundColumn.UniqueName = "Data2";
      boundColumn.Exportable = true;
      toolTipGrid.MasterTableView.Columns.Add(boundColumn);
 
      // Export stuff
      toolTipGrid.MasterTableView.CommandItemSettings.ShowExportToExcelButton = true;
      toolTipGrid.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = false;
      toolTipGrid.MasterTableView.CommandItemSettings.ShowRefreshButton = false;
      toolTipGrid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Bottom;
 
      toolTipGrid.ItemCommand += toolTipGrid_ItemCommand;                      
 
      toolTipGrid.AllowPaging = true;
      toolTipGrid.PageSize = 20;
      toolTipGrid.PagerStyle.Mode = GridPagerMode.NextPrev;
      toolTipGrid.NeedDataSource += CargoMileageInfo_NeedDataSource;
                 
      toolTipGrid.DataSource = DataForToolTip;
      toolTipGrid.DataBind();
 
      panel.ContentTemplateContainer.Controls.Add(toolTipGrid);       
}

 

The button triggers the toolTipGrid_ItemCommand

private void toolTipGrid_ItemCommand(object sender, GridCommandEventArgs e)
{
    RadGrid toolTipGrid= (RadGrid)sender;
 
    if (e.CommandName == RadGrid.ExportToExcelCommandName)
    {
        toolTipGrid.ExportSettings.Excel.Format = GridExcelExportFormat.Xlsx;
        toolTipGrid.ExportSettings.IgnorePaging = true;
        toolTipGrid.ExportSettings.ExportOnlyData = true;
        toolTipGrid.ExportSettings.OpenInNewWindow = true;
    }
}

 

Advance DataBind:

private void toolTipGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    RadGrid toolTipGrid= (RadGrid)sender;
 
    toolTipGrid.DataSource = DataForToolTip;
}

 

 

 

This may be related, but I have debugged and stepped through my code to see where it breaks when the button is clicked, and I get this error, "JavaScript runtime error: Unable to get property 'Cols' of undefined or null reference occurred."

1 Answer, 1 is accepted

Sort by
0
Accepted
Attila Antal
Telerik team
answered on 10 Apr 2019, 02:25 PM
Hi Peter,

RadAjaxManager or RadAjaxPanel controls have been configured to exclude exporting events from the AJAX request automatically if they are coming from the built-in buttons of RadGrid, thus you will need to implement anything additional.

The problem you are facing is most likely to be due to the way the RadGrid is created programmatically and also because of calling the DataBind() method (inside UpdateToolTip function) for a grid that is using the Advanced Data-binding (Using NeedDataSource Event). This article describes the DataBind() method must not be called when binding data to RadGrid using advanced data binding.

Please examine the Creating the Grid Entirely in the Code Behind article where there are several examples describing how to create a RadGrid programmatically and ensure that the grid is being created accordingly. Further more, I would like mention, when using the Init event, everything is being created every time, while within the Load event, only the RadGrid object and events are created at every load, columns and other properties are being added only once, at initial load.

Also, it is very important to follow the correct order when creating column. For example, using the Page Init event, a GridColumn object is created, properties configured and finally added to the Columns collection. On the other hand, if using Page Load, once the GridColumn object is created will be added directly to the Columns collection and only after that configuring the Properties. 

I hope the above information will prove useful and help you resolve the issue.

Kind regards,
Attila Antal
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Peter
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Share this question
or