This is a migrated thread and some comments may be shown as answers.

Excel Export not working correctly after datasource refreshing data

5 Answers 881 Views
Grid
This is a migrated thread and some comments may be shown as answers.
reader
Top achievements
Rank 1
reader asked on 06 Feb 2015, 11:54 PM
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


5 Answers, 1 is accepted

Sort by
0
reader
Top achievements
Rank 1
answered on 09 Feb 2015, 10:38 PM
Anyone has a solution for this? So basically, export will export data that is initialized in the first time. dataSource.read() will affect the grid, we can see the new results, but it does not affect the export. Is it because the initialized data cached somewhere and not updated when it reads new data?

what's the correct way to update the dataSource for the grid?

I'm sure many users will have this case, nobody had the issue?

Thanks


0
Kiril Nikolov
Telerik team
answered on 10 Feb 2015, 04:43 PM

Hello,

 

You have two options to resolve this issue:

 

1. Set the transport.read.url option to a function that is dynamically resolved when needed, as setting the url with options.read.url = url is not supported. Here is the documentation about it:

http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-transport.read.url

 

2. You can create a new dataSource with the new url, and then use the setDataSource() method of the grid to change the dataSource. Here is the documentation about it:

 

http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#methods-setDataSource

 

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
yaron
Top achievements
Rank 1
answered on 09 May 2016, 05:50 AM

Same problam here

i tryied your two option , none worked.

any idea ?

0
yaron
Top achievements
Rank 1
answered on 09 May 2016, 06:19 AM

found the solution !
after refreshing the data source with new parameters,
you should set the filter option on the dataSource with the new params.

for example i refresh the data like this :

grid.dataSource.filter(newfilters);

i add the next row of code to solve the problam :

grid.dataSource.options.filter=newfilters;

0
Kiril Nikolov
Telerik team
answered on 10 May 2016, 06:55 AM
Hello,

I am happy to hear that you found a solution for this.

In case you have any further questions - please open a separate support request and we will be happy to help.

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
reader
Top achievements
Rank 1
Answers by
reader
Top achievements
Rank 1
Kiril Nikolov
Telerik team
yaron
Top achievements
Rank 1
Share this question
or