We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Export to Excel

Thread ID:

Created:

Updated:

Platform:

Replies:

132999 Oct 3,2017 11:05 AM Oct 5,2017 10:41 AM ASP.NET MVC 3
loading
Tags: Grid
Gian Carlo
Asked On October 3, 2017 11:05 AM

Hi, im trying to export an info from the datagrid, the problem comes when i exported, it says no data to show, also if i only put 1 parameter it doesnt print the current displayed info. how can i solve this?
--------------------------------------------------------------------------
@Html.EJ().DatePicker("DatePick").EnablePersistence(true).Width("100%").DateFormat("yyyy-MM-dd").Locale("es-ES").WatermarkText("Fecha Inicial")
@Html.EJ().DatePicker("DatePick2").EnablePersistence(true).Width("100%").DateFormat("yyyy-MM-dd").Locale("es-ES").WatermarkText("Fecha Final")
@(Html.EJ().Button("btnSearchFlight")
.Text(" Search")
.ShowRoundedCorner()
.ClientSideEvents(e => { e.Click("btnSearchClick"); })
)
--------------------------------------------------------------------------
@(Html.EJ().Grid("grid")
.Datasource((IEnumerable)ViewBag.vTerritorio)
.AllowSorting()
.AllowGrouping()
.AllowPaging()
.GroupSettings(group => { group.ShowToggleButton(false).EnableDropAreaAnimation(false); })
.Locale("es-ES")
//.PageSettings(p => p.PageSize(15))
.IsResponsive()
.ToolbarSettings(toolbar => { toolbar.ShowToolbar().ToolbarItems(items => {
items.AddTool(ToolBarItems.Search);
items.AddTool(ToolBarItems.ExcelExport);
items.AddTool(ToolBarItems.PdfExport);
}); })
.SummaryRow(row =>
{
row.ShowTotalSummary(false)
.SummaryColumns(col =>
{
col.SummaryType(SummaryType.Sum)
.DisplayColumn("Cantidad")
.DataMember("Cantidad")
.Add();
col.SummaryType(SummaryType.Sum)
.DisplayColumn("VentaValor")
.DataMember("VentaValor")
.Format("{0:C}")
.Add();
}).Add();
})
.Columns(col =>
{
//col.Field("Tipo").HeaderText("Tipo").Width(100).Add();
col.Field("FechaDocumento").HeaderText("Fecha").Format("{0:dd/MM/yyyy}").Width(150).Add();
col.Field("CodigoArticulo").HeaderText("Codigo").Width(150).Add();
col.Field("DescripcionArticulo").HeaderText("Descripcion").Width(500).Add();
col.Field("Cantidad").HeaderText("Cantidad").TextAlign(TextAlign.Center).Width(75).Width(150).Add();
col.Field("PrecioVenta").HeaderText("PrecioVenta").Format("{0:C}").Width(150).TextAlign(TextAlign.Center).Add();
col.Field("VentaValor").HeaderText("VentaValor").Format("{0:C}").TextAlign(TextAlign.Center).Width(75).Width(150).Add();
col.Field("DescripcionTerritorio").HeaderText("Territorio").Add();
})
.ClientSideEvents(eve => { eve.QueryCellInfo("formatingCell");
}))
--------------------------------------------------------------------------
function btnSearchClick(sender) {
var f1 = document.getElementById("DatePick").value;
var f2 = document.getElementById("DatePick2").value;
console.log(f1 + ' ' + f2);
$.ajax({
url: "/Ventas/DataSourceVentas2",
type: "POST",
data: {
date1: f1,
date2: f2
},
success: function (result) {
var formatData = ej.parseJSON(result);
var obj = $("#grid").ejGrid("instance");
obj.dataSource(result);
obj.dataSource(formatData);
}
});
}
--------------------------------------------------------------------------
public void ExportToPdf(string GridModel, string date1, string date2)
{
PdfExport exp = new PdfExport();
RepoDapper propRep = new RepoDapper();
var company = HttpContext.GetOwinContext().GetUserManager().FindById(User.Identity.GetUserId()).CodCompany;
var venBodega = propRep.ReadVenTerritorio2(fecha1, fecha2, company);
GridProperties obj = ConvertGridObject(GridModel);
exp.Export(obj, venBodega, "Export.pdf", false, false, "flat-saffron");
}
-

Vignesh Natarajan [Syncfusion]
Replied On October 4, 2017 02:06 PM

Hi Gian, 


Thanks for Using Syncfusion Products. 


We have analyzed your query and we are not able to reproduce the reported issue. You have mentioned if you use one parameter also the grid is not exporting. 


Please refer the below code snippet 

C# 

public void ExportToExcel(string GridModel) 
        { 
            ExcelExport exp = new ExcelExport(); 
            GridProperties obj = ConvertGridObject(GridModel); 
            exp.Export(obj, currentData, "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-saffron"); 
        } 
                    .   
                    . 
                    .  
 
        private GridProperties ConvertGridObject(string gridProperty) 
        { 
                    . 
                    . 
                    .         
        } 



JS 

function btnSearchClick(sender) { 
            var f1 = document.getElementById("DatePick").value; 
            var f2 = document.getElementById("DatePick2").value; 
            console.log(f1 + ' ' + f2); 
            $.ajax({ 
                url: "/Grid/DataSourceVentas2", 
                type: "POST", 
                data: { 
                    date1: f1, 
                    date2: f2 
                }, 
                success: function (result) { 
                    var formatData = ej.parseJSON(result); 
                    var obj = $("#FlatGrid").ejGrid("instance"); 
                    obj.dataSource(result); 
                    obj.dataSource(formatData); 
                } 
            }); 
        } 

We assumed that you have filtered the dataSource based on the date value and on ajax success, updated the Grid dataSource.  We have exported the updated dataSource through toolbarclick event of Grid. In toolbarClick event we have passed the dataSource object to exported file.  

Refer the below code snippet  

  .ClientSideEvents(evt => evt.ToolbarClick("OnToolbarClick")) 
         ) 
    <script type="text/javascript"> 
        function OnToolbarClick(args) { 
            if (args.itemName.indexOf("Export") > -1) {//if no selectedRecords, currenviewdata will be exported 
                this.model["currentData"] = JSON.stringify(this.model.dataSource); 
            } 
        } 



Please refer the below sample. 




Please provide the following details to help you better  

  1. Full Grid Code(Cshtml and controller page)
  2. Screenshot of Exception error / script error in console window(if any)
  3. Kindly share more details what you want to do with the two datePicker value while exporting the Grid.


Note: Exporting function cannot take more than one argument. So, we suggest you to use only one parameter. 


Regards, 
Vignesh Natarajan. 


Gian Carlo
Replied On October 4, 2017 05:28 PM

Thx a lot, this solve my day 


Vignesh Natarajan [Syncfusion]
Replied On October 5, 2017 10:41 AM

Hi Gian, 

We are happy to hear that your issue has been resolved. 

please get back to us if you need any further assistance. 

Regards, 
Vignesh Natarajan 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;