<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<ej:Grid ID="FlatGrid" runat="server" AllowSorting="True" DataSourceID="SqlData" AllowGrouping="true" OnServerWordExporting="FlatGrid_ServerWordExporting" OnServerPdfExporting="FlatGrid_ServerPdfExporting" OnServerExcelExporting="FlatGrid_ServerExcelExporting" AllowPaging="True" AllowFiltering="True" > <ToolbarSettings ShowToolbar="true" ToolbarItems="excelExport,wordExport,pdfExport"></ToolbarSettings> <FilterSettings FilterType="Excel"></FilterSettings> <ClientSideEvents DataBound="databound" /> </ej:Grid> <asp:SqlDataSource ID="SqlData" runat="server" ConnectionString="<%$ ConnectionStrings:NORTHWNDConnectionString %>" SelectCommand="SELECT * FROM [Territories]"></asp:SqlDataSource> <script type="text/javascript"> function databound(args) { this.model.summaryRows.push({ title: "Sum", summaryColumns: [{ summaryType: ej.Grid.SummaryType.Sum, displayColumn: this.model.columns[2].headerText, dataMember: this.model.columns[2].headerText, format: "{0:C2}", prefix: "Sum =" }] }); $("#MainContent_FlatGrid").ejGrid("model.showSummary", true); } </script> |
protected void FlatGrid_ServerExcelExporting(object sender, Syncfusion.JavaScript.Web.GridEventArgs e) { ExcelExport exp = new ExcelExport(); DataView data = (DataView)SqlData.Select(new DataSourceSelectArguments()); IList data1 = data; DataTable dt = data.Table; var emp = (from DataRow row in dt.Rows
select new Order { TerritoryID = Convert.ToInt32(row["TerritoryID"]), TerritoryDescription = row["TerritoryDescription"].ToString(), RegionID = Convert.ToInt32(row["RegionID"]), }).ToList(); IWorkbook workbook = exp.Export(FlatGrid.Model, (IEnumerable)emp, "Export.xlsx", ExcelVersion.Excel2010, true, true, "flat-lime", true); exp.Export(FlatGrid.Model, (IEnumerable)emp, "Export.xlsx", ExcelVersion.Excel2010, true, true, "flat-lime", false, workbook, MultipleExportType.AppendToSheet, "Flat Grid"); |
Please try the attached sample and still if you face the issue, please reproduce the issue in the sample and send back.
Regards,
Prasanna Kumar N.S.V
<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent"> <ej:Grid runat="server" ID="gridDatos" AllowPaging="true" AllowGrouping="true" AllowScrolling="true" AllowFiltering="true" AllowTextWrap="true" AllowResizing="true" AllowResizeToFit="true" OnServerExcelExporting="gridDatos_ServerExcelExporting" DataSourceID="SqlDSResumen"> <ToolbarSettings ShowToolbar="true" ToolbarItems="excelExport"></ToolbarSettings> <GroupSettings GroupedColumns="Area" ShowDropArea="true" /> <FilterSettings FilterType="Excel"></FilterSettings> <ClientSideEvents DataBound="databound" />
</ej:Grid>
---------------------------
<script type="text/javascript">
function databound(args) {
this.model.summaryRows.push({ title: "Sum", summaryColumns: [{ summaryType: ej.Grid.SummaryType.Sum, displayColumn: this.model.columns[2].headerText, dataMember: this.model.columns[2].headerText, format: "{0:C2}", prefix: "Sum =" }] });
$("#" + args.model.clientId).ejGrid("model.showSummary", true);
}
|
protected void gridDatos_ServerExcelExporting(object sender, Syncfusion.JavaScript.Web.GridEventArgs e) { ExcelExport exp = new ExcelExport(); DataView datos = (DataView)SqlDSResumen.Select(DataSourceSelectArguments.Empty); DataTable dt = datos.Table; var emp = (from DataRow row in dt.Rows
select new Order { Area = row["Area"].ToString(), Provincia = row["Provincia"].ToString(), Week10 = Convert.ToInt32(row["Week10"]), Week11 = Convert.ToInt32(row["Week11"]), Week13 = Convert.ToInt32(row["Week13"]), }).ToList(); exp.Export(gridDatos.Model, (IEnumerable)emp, "Export.xlsx", ExcelVersion.Excel2010, true, true, "flat-lime"); } } }
public class Order { public string Area { get; set; } public string Provincia { get; set; } public int Week10 { get; set; } public int Week11 { get; set; } public int Week13 { get; set; } |
Queries |
Response |
“DataTable support for exporting feature” |
While using sqlDataSource the Grid that has DataTable as its datasource. Currently we do not have Data table support for exporting feature. For that we have already logged the feature request “Need to provide DataTable support for Exporting feature” A support incident has been created under your account to resolve the issue. Please log on to our support website to check for further updates.
https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents |
“DataSource must not be empty at initial load since columns are generated from database” |
It’s mandatory to provide either datasource or initializing column while rendering Grid. We cannot render the Grid without anyone of these two. If we do not provide columns then the column will be generated using the datasource. So, we need to provide anyone to avoid the alert box. |
Hi Manolo,
We have provided “DataTable Support for exporting” from v14.1.0.41. So if you are using older version, please upgrade to the new version.We have created a sample, which can be downloaded from below location.
Regards,
Jayaprakash K.