Kendo user interface: Excel Export does not work correctly after updating datasource data

I have a grid, when users click the button, it receives some parameters and updates the data source:

var grdUP = $("#weblogGrid").data("kendoGrid");
grdUP.dataSource.transport.options.read.url = url; // new url

//Read data source to update
grdUP.dataSource.read();

It works great. new data is displayed in the grid. And the grid has another button that will export data to Excel. I use the code below (also tried the built-in button):

var grid = $("#weblogGrid").data("kendoGrid");
grid.saveAsExcel();

it actually exports the data to an excel file.

However, it always exports the source data to the grid, rather than updating the data user.

For example, when a grid is first displayed, it has 10 rows of data. After the upgrade, it has 5 rows of data. Now, if exported, it still exports 10 rows of data, although the data in the grid is different.

? , , - ?

=============================== , -

. , :

var url = '/WeblogReport/GetWebLogList?fromDate=' + fromDate + '&toDate=' + toDate;
var grdUP = $("#myGrid").data("kendoGrid");
//Set url property of the grid data source
grdUP.dataSource.transport.options.read.url = url;
//Read data source to update
grdUP.dataSource.read();

, :

// get value of date
....

$.ajax({
    type: "GET",
    dataType: "json",
    url: "/WeblogReport/GetWebLogList",
    data: { FromDate: fromDate, ToDate: toDate },
    success: function (data) {
        alert(data);

        var grid = $("#myGrid").data("kendoGrid");

        grid.dataSource.data(data);
        grid.refresh();
    }
});

- . - ?

.


Json.

success: function (data) {
    var newdata = [{ "UserName": "username", "ClientIP": "1.1.1.1"}];

    $("#myGrid").data("kendoGrid").dataSource.data(newdata);
    $("#myGrid").data("kendoGrid").refresh();

    //$("#myGrid").data("kendoGrid").saveAsExcel();
}
+4
4

:

http://jsfiddle.net/Sowjanya51/o8cw3vj8/

$('#grid1').data('kendoGrid').dataSource.data(newdata);  
$('#grid1').data('kendoGrid').refresh();    

dataSource , gridSourceSource - , .

0

"allPages" "". :

excel: {
    fileName: "Export.xlsx",
    filterable: true,
    allPages: true
},
0

, .

var grdUP = $("#weblogGrid").data("kendoGrid");
grdUP.dataSource.transport.options.read.url = url; // new url

//Read data source to update
grdUP.dataSource.read();
//add this line to refresh the active data set in the grid
grdUP.refresh();

I ran into the same problem and this resolved this for me. The only difference between your approach and mine is that you change the read URL of the data source, while I change the data parameters for the read method. It doesn't matter, but I mentioned it just in case.

0
source

Set both of the following fields for Excel export to work:

grid.dataSource.transport.options.read.url = url;
grid.options.dataSource.transport.read.url = url;
0
source

All Articles