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

export selected only

3 Answers 120 Views
Grid
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 04 Oct 2010, 07:20 PM
I am trying to export only the selected items from a grid. But it exports everything. Here is grid, which is dynamically defined.

<telerik:RadGrid ID="DisplayDataGrid" runat="server" AutoGenerateColumns="False"
               AllowMultiRowSelection="True" AllowSorting="True" AllowPaging="True" PageSize="6"
               OnNeedDataSource="Grid_NeedDataSource" OnItemCreated="ImageryGrid_ItemCreated"
               ShowStatusBar="true" Width="100%" GridLines="None" Skin="Hay" ItemStyle-Font-Size="7pt"
               AlternatingItemStyle-Font-Size="7pt">
               <ClientSettings EnableRowHoverStyle="true">
                   <Scrolling AllowScroll="True" ScrollHeight="230px" UseStaticHeaders="false" />
                   <Selecting AllowRowSelect="true" />
               </ClientSettings>
               <ExportSettings IgnorePaging="true" OpenInNewWindow="true" FileName="ImageryExcel"
                   ExportOnlyData="true" />
               <MasterTableView HeaderStyle-Wrap="false" TableLayout="Fixed">
                   <PagerStyle AlwaysVisible="True" FirstPageToolTip="" LastPageToolTip="" NextPagesToolTip=""
                       PrevPagesToolTip="" PrevPageToolTip="" NextPageToolTip="" />
               </MasterTableView>
           </telerik:RadGrid>

Here is the export button click, which works for exporting everything, but it does not handle selected items.

Public Sub ButtonExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonExcelIMG.Click
        AssignGridDataSource()
        DisplayDataGrid.DataBind()
 
        DisplayDataGrid.MasterTableView.Columns.FindByUniqueName("ClientSelectColumn").Visible = False
         
        DisplayDataGrid.ExportSettings.ExportOnlyData = True
        DisplayDataGrid.ExportSettings.OpenInNewWindow = True
 
        If DisplayDataGrid.SelectedItems.Count > 0 Then
 
            For Each dataItem As GridDataItem In DisplayDataGrid.MasterTableView.Items
            '    If dataItem.Selected Then
            '        DisplayDataGrid.MasterTableView.
            '    End If
                dataItem.Visible = dataItem.Selected
                dataItem.Enabled = dataItem.Selected
                dataItem.Display = dataItem.Selected
 
            Next
        End If
 
        'Export to Excel
        DisplayDataGrid.MasterTableView.ExportToExcel()
    End Sub

Here is the dynamic creation of the select column. The other columns are created in a similar way.
DisplayDataGrid.Columns.Clear()
Dim tcolumn As GridHyperLinkColumn = New GridHyperLinkColumn
Dim clientGrid As GridClientSelectColumn = New GridClientSelectColumn
 
' Checkbox
clientGrid.UniqueName = "ClientSelectColumn"
clientGrid.HeaderStyle.Width = Unit.Pixel(25)
clientGrid.ItemStyle.ForeColor = Color.RoyalBlue
clientGrid.ItemStyle.HorizontalAlign = HorizontalAlign.Center
clientGrid.ItemStyle.Width = Unit.Pixel(25)
DisplayDataGrid.Columns.Add(clientGrid)

Any idea why it is not only doing the selected items? 

Thanks!

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 08 Oct 2010, 02:22 PM
Hello William,

You have to set IgnorePaging="false" in order to export the selected rows in this case. Otherwise you should persist the selected items manually and then use the ItemCreated event to hide the items that are not selected.
Note that IgnorePaging=true"  will cause RadGrid to rebind since it have to get all items from the datasource.

Best regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
William
Top achievements
Rank 1
answered on 08 Oct 2010, 08:41 PM
Ok, I tried that....But now I am getting another issue.

Here is what I changed in the Excel button click event
For Each dataItem As GridDataItem In DisplayDataGrid.MasterTableView.GetSelectedItems()
     If dataItem.Selected Then
          DisplayDataGrid.ExportSettings.IgnorePaging = False
     End If
     dataItem.Visible = dataItem.Selected
Next

Even if the item is selected... dataItem.Selected is always false. Do I need to do something to link up the gridclientselectcolumn to the .Selected property?

Also my columns are created dynamically in code as opposed to in the aspx 
Dim clientGrid As GridClientSelectColumn = New GridClientSelectColumn
clientGrid.UniqueName = "ClientSelectCoulumn"
clientGrid.HeaderStyle.Width = Unit.Pixel(25)
clientGrid.ItemStyle.ForeColor = Color.RoyalBlue
clientGrid.ItemStyle.HorizontalAlign = HorizontalAlign.Center
clientGrid.ItemStyle.Width = Unit.Pixel(25)
DisplayDataGrid.Columns.Add(clientGrid)


Thanks!
0
Daniel
Telerik team
answered on 14 Oct 2010, 03:59 PM
Hello William,

Please download the attached project that demonstrates how to export the selected items when IgnorePaging is set to "true". Note that the currently selected items are persisted manually.

Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
William
Top achievements
Rank 1
Answers by
Daniel
Telerik team
William
Top achievements
Rank 1
Share this question
or