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

Hierarchy RadGrid Export to pdf DetailTables

1 Answer 152 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marie
Top achievements
Rank 1
Marie asked on 23 Dec 2014, 02:51 PM
Hi, I want to know if I can export to pdf only one row from my grid NOT all grid.
I have only two(2) levels hierarchy. I want to export only the level 2.
I select one row, I pick export to pdf and voilĂ ... I export only the level 2, or the text inside the row...
I put this code and I can't see the buttons neither: <CommandItemSettings ShowExportToWordButton="false" ShowExportToExcelButton="true" ShowExportToCsvButton="false" ShowExportToPdfButton="true" ShowAddNewRecordButton="false" ShowRefreshButton="false"/>




http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/insert-update-delete-hierarchy/defaultcs.aspx?skin=WebBlue

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 26 Dec 2014, 09:14 AM
Hi Marie,

If you want to export the structure of a nested DetailTable from a selected item you can handle the server-side OnItemCommand event when the CommandName is equal to RadGrid.ExportToPdfCommandName, cancel the command, get reference to the selected item and then to the nested TableView and call the ExportToPdf method of that TableView. This will export only the nested TableView:
<telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand" OnDetailTableDataBind="RadGrid1_DetailTableDataBind">
    <MasterTableView CommandItemDisplay="Top" CommandItemSettings-ShowExportToPdfButton="true">
        <DetailTables>
            <telerik:GridTableView Name="Level2"></telerik:GridTableView>
        </DetailTables>
    </MasterTableView>
    <ClientSettings>
        <Selecting AllowRowSelect="true" />
    </ClientSettings>
</telerik:RadGrid>

And the code-behind:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    DataTable table = new DataTable();
    table.Columns.Add("ID", typeof(int));
    table.Columns.Add("Level1", typeof(string));
    for (int i = 0; i < 5; i++)
    {
        table.Rows.Add(i, "Level1_" + i);
    }
 
    (sender as RadGrid).DataSource = table;
}
 
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.ExportToPdfCommandName)
    {
        e.Canceled = true;
        if (RadGrid1.MasterTableView.GetSelectedItems().Count() > 0)
        {
            GridDataItem selectedItem = RadGrid1.MasterTableView.GetSelectedItems()[0];
            if (selectedItem.Expanded)
            {
                selectedItem.ChildItem.NestedTableViews[0].ExportToPdf();
            }  
        }
    }
}
 
protected void RadGrid1_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
{
    if (e.DetailTableView.Name == "Level2")
    {
        DataTable table = new DataTable();
        table.Columns.Add("ID", typeof(int));
        table.Columns.Add("Level2", typeof(string));
        for (int i = 0; i < 5; i++)
        {
            table.Rows.Add(i, "Level2_" + i);
        }
 
        e.DetailTableView.DataSource = table;
    }
}

As for displaying the export buttons, you should set the CommandItemDisplay property of the MasterTableView.

In my opinion, the more appropriate way for handling this would be to show the export button to the nested TableViews only, which will have the same result.

Hope this helps.


Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Marie
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or