4
votes

I have a Grid, when users click a button, it gets some parameters and refresh datasource:

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

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

it works fine. the new data shows in the grid. And the grid has another button, which will export the data to excel. I'm using below code (also tried the built-in button):

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

it actually exports the data to excel file.

However, it always exports the initial data in the grid, not the data user refreshed.

For example, when the grid first shows up, it has 10 rows data. After refresh, it has 5 rows data. Now, if export, it still exports 10 rows data although the data in grid is different.

Is this a Bug? or, maybe I did something wrong in refresh grid?

Thanks

=============================== edit to clarify something

Thanks. currently, I got new data using:

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();

So I changed to:

// 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();
    }
});

Somehow, it does not show the new data. Any suggestions?

Thank you very much.


add more clarification

Here is in the Json call.

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 Answers

1
votes

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

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

check this:

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

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

You need to update the dataSource and reload the grid,otherwise the grid dataSource will still have reference to old data even though UI displays the new data.

0
votes

Just set the "allPages" option on your grid to "True". like so :

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

Your original solution should be fine if you refresh the grid after you read from 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();
//add this line to refresh the active data set in the grid
grdUP.refresh();

I had run into the same issue and this solved it for me. The only difference between your approach and mine is that you're changing the data source's read URL, whereas I was changing the data parameters for the read method. Shouldn't make any difference, but I'll mention that just in case.