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. Image for the cookie policy date

Export to Excel

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<object>)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");
}
-


3 Replies

VN Vignesh Natarajan Syncfusion Team October 4, 2017 06:06 PM UTC

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. 



GC Gian Carlo October 4, 2017 09:28 PM UTC

Thx a lot, this solve my day 



VN Vignesh Natarajan Syncfusion Team October 5, 2017 02:41 PM UTC

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 


Loader.
Up arrow icon