Telerik Grid - export more columns to CSV than displayed on screen

Problem: How to display more columns in the Telerik grid than are displayed in the rendering grid?

For example, I would like to display the last name only on the screen, but on a dump on csv it would also be useful.

I tried visible = false and display = false in GridBoundColumns, but then they don't go to csv.

<telerik:RadGrid ID="grdAuctions" runat="server" AllowAutomaticDeletes="True" AllowAutomaticUpdates="True"
        AllowPaging="False" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="odsAuctionSales"
        GridLines="None" EnableEmbeddedSkins="False" OnItemDataBound="grdAuctionSales_ItemDataBound">
        <ExportSettings HideStructureColumns="true" />
        <MasterTableView Width="100%" CommandItemDisplay="Top">
            <PagerStyle Mode="NextPrevNumericAndAdvanced" />
            <CommandItemSettings ShowAddNewRecordButton="false" ShowRefreshButton="false" ShowExportToCsvButton="true"
                ExportToCsvImageUrl="~/Images/excel.jpg" ExportToCsvText="Export to csv" />
        </MasterTableView>
        <MasterTableView DataKeyNames="Id" DataSourceID="odsAuctionSales" CssClass="listItems"
            Width="98%">
            <SortExpressions>
                <telerik:GridSortExpression FieldName="Name"></telerik:GridSortExpression>
            </SortExpressions>
            <RowIndicatorColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>
            <ExpandCollapseColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridTemplateColumn UniqueName="Edit">
                    <ItemTemplate>
                        <asp:HyperLink ID="edit" runat="server" Text="Edit"></asp:HyperLink>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn DataField="NameOnTable" HeaderText="Name On Table" SortExpression="NameOnTable"
                    UniqueName="NameOnTable">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Surname" HeaderText="Surname" SortExpression="Surname"
                    UniqueName="Surname">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Firstname" HeaderText="Firstname" SortExpression="Firstname"
                    UniqueName="Firstname">
                </telerik:GridBoundColumn>

Edit That's how I got the job.

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.ExportToCsvCommandName)
        {
            grdAuctions.MasterTableView.GetColumn("Edit").Visible = false;
            grdAuctions.MasterTableView.GetColumn("DPSAuthCode").Visible = true;
    grdAuctions.MasterTableView.ExportToCSV();
        }

    }

and in aspx

OnItemCommand="RadGrid1_ItemCommand"

and

 <telerik:GridBoundColumn DataField="DPSAuthCode" HeaderText="DPSAuthCode" Visible="false"
                    SortExpression="DPSAuthCode" UniqueName="DPSAuthCode">
                </telerik:GridBoundColumn>
+3
source share
2 answers

Switching the value of the Visible or Display property before calling the export should do the trick. See the section (Hide columns) here for details .

+3
source

, , - , jquery, .

csv, Telerik, - .

0

Source: https://habr.com/ru/post/1781367/


All Articles