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

RadGrid - CSV exported doesn't display cell values

1 Answer 46 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
EEmmanuelLG
Top achievements
Rank 1
EEmmanuelLG asked on 17 Feb 2018, 08:52 PM

I have a RadGrid with a datasource and I added 4 more columns manually and I populate these 4 columns in the server side.

When I try to export the RadGrid data, the 4 columns that I added manually doesn't display the cell values.

Is there a configuration that I have to set?

Code client-side:

<telerik:RadGrid ID="radGridOLAUtilization" runat="server" AllowFilteringByColumn="True" AllowSorting="True" DataSourceID="sqlDataSource" CellSpacing="-1" >
    <ExportSettings ExportOnlyData="true" ></ExportSettings>
    <GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>
    <ClientSettings>
        <Scrolling AllowScroll="True" UseStaticHeaders="False" />
    </ClientSettings>
    <MasterTableView DataSourceID="sqlDataSource" AutoGenerateColumns="False" UseAllDataFields="true">
        <Columns>
            <telerik:GridBoundColumn DataField="PalletID" DataType="System.Int32" FilterControlAltText="Filter PalletID column" HeaderText="Pallet ID" SortExpression="PalletID" UniqueName="PalletID" HeaderStyle-HorizontalAlign="Center">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Station" FilterControlAltText="Filter Station column" HeaderText="Station" SortExpression="Station" UniqueName="Station" HeaderStyle-HorizontalAlign="Center">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="StartDateTime" DataType="System.DateTime" FilterControlAltText="Filter StartDateTime column" HeaderText="Start DateTime" SortExpression="StartDateTime" UniqueName="StartDateTime" HeaderStyle-HorizontalAlign="Center">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="EndDateTime" DataType="System.DateTime" FilterControlAltText="Filter EndDateTime column" HeaderText="End DateTime" SortExpression="EndDateTime" UniqueName="EndDateTime" HeaderStyle-HorizontalAlign="Center">                  </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="DeltaTime" DataType="System.TimeSpan" FilterControlAltText="Filter DeltaTime column" HeaderText="Delta Time" ReadOnly="True" SortExpression="DeltaTime" UniqueName="DeltaTime" HeaderStyle-HorizontalAlign="Center">
            </telerik:GridBoundColumn>
                    <!-- Columns added manually -->
               <telerik:GridBoundColumn DataField="TotalTime" DataType="System.TimeSpan" FilterControlAltText="Filter TotalTime column" HeaderText="Total Time" ReadOnly="True" SortExpression="TotalTime" UniqueName="TotalTime" HeaderStyle-HorizontalAlign="Center">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn Display="false" DataField="DownTime" DataType="System.TimeSpan" FilterControlAltText="Filter DownTime column" HeaderText="DownTime" ReadOnly="True" SortExpression="DownTime" UniqueName="DownTime" HeaderStyle-HorizontalAlign="Center">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataType="System.TimeSpan" FilterControlAltText="Filter AccumulatedDownTime column" HeaderText="Accumulated DownTime" ReadOnly="True" SortExpression="AccumulatedDownTime" UniqueName="AccumulatedDownTime" HeaderStyle-HorizontalAlign="Center">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataType="System.String" FilterControlAltText="Filter UtilizationTime column" HeaderText="Utilization Time" ReadOnly="True" SortExpression="UtilizationTime" UniqueName="UtilizationTime" HeaderStyle-HorizontalAlign="Center">
</telerik:GridBoundColumn>
</Columns>
    </MasterTableView>
</telerik:RadGrid>

Server-side:

protected void Page_Load(object sender, EventArgs e)
        {
            double AccumulatedDeltaTime = 0;
 
            for (int i = 0; i < radGridOLAUtilization.Items.Count; i++)
            {
                TableCell accumulatedDownTimeCell = radGridOLAUtilization.Items[i]["AccumulatedDownTime"];
                TableCell DownTimeCell = radGridOLAUtilization.Items[i]["DownTime"];
                TableCell deltaTimeCell = radGridOLAUtilization.Items[i]["DeltaTime"];
                TableCell accumulatedUtilizationTimeCell = radGridOLAUtilization.Items[i]["UtilizationTime"];
                TableCell totalTimeCell = radGridOLAUtilization.Items[i]["TotalTime"];
                AccumulatedDeltaTime += TimeSpan.Parse(deltaTimeCell.Text).TotalSeconds;
                 
                if (i == 0)
                {
                    accumulatedDownTimeCell.Text = "00:00:00";
                    accumulatedUtilizationTimeCell.Text = "100%";
                    totalTimeCell.Text = deltaTimeCell.Text;
                }
                else
                {
                    TableCell previousAccumulatedDownTimeCell = radGridOLAUtilization.Items[i - 1]["AccumulatedDownTime"];
                    TableCell previousTotalTimeCell = radGridOLAUtilization.Items[i - 1]["TotalTime"];
                    double accumulatedDownTime = TimeSpan.Parse(previousAccumulatedDownTimeCell.Text).TotalSeconds + TimeSpan.Parse(DownTimeCell.Text).TotalSeconds;
                    accumulatedDownTimeCell.Text = TimeSpan.FromSeconds(accumulatedDownTime).ToString();
                    int accumulatedUtilizationTime = (int)(100 * AccumulatedDeltaTime / (AccumulatedDeltaTime + accumulatedDownTime));
                    accumulatedUtilizationTimeCell.Text = accumulatedUtilizationTime.ToString() + "%";
                    double totalTime = AccumulatedDeltaTime + accumulatedDownTime;
                    totalTimeCell.Text = TimeSpan.FromSeconds(totalTime).ToString();
                }
            }
        }
     
        protected void btnExportToExcel_Click(object sender, EventArgs e)
        {
            //radGridOLAUtilization.ExportSettings.Excel.Format = GridExcelExportFormat.Xlsx;
            radGridOLAUtilization.ExportSettings.FileName = "Alerts Data";
            radGridOLAUtilization.ExportSettings.IgnorePaging = true;
            //radGridOLAUtilization.MasterTableView.ExportToExcel();
            radGridOLAUtilization.MasterTableView.ExportToCSV();
        }

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 21 Feb 2018, 08:56 AM
Hi,

When you are using the IgnorePaging property, the grid is getting rebound internally just before exporting. Therefore, it gets the original data from the initial source. You can try to remove this property or set the custom text in the ItemDataBound event handler:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows

I hope this will prove helpful.

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
General Discussions
Asked by
EEmmanuelLG
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or