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

[Solved] Excel Export data source

4 Answers 472 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Greg
Top achievements
Rank 1
Greg asked on 17 Dec 2014, 05:51 PM
Hi,

I have a Grid that I change the data source read URL of dynamically, which works great for updating the data shown in the grid. The data source URL is always targeting a HTTP URI. I've attempted to add the Export to Excel functionality to this grid now, however clicking the export button always sends a HTTP request to the current page (with filter/sorting/etc query parameters) and not to the data source URI.

I have used a simple test grid with a local data source and exporting that works fine.

Can anyone shed some light on this please?

Cheers.

4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 19 Dec 2014, 11:25 AM
Hello Greg,

This sounds as a known issue that we have fixed in the latest internal build. Could you download it and give it a try? If the internal build doesn't resolve the issue - could you provide some sample code that shows how you change the read URL?

Regards,
Atanas Korchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Greg
Top achievements
Rank 1
answered on 22 Dec 2014, 12:34 PM
Hi Atanas,

Thanks for the suggestion, unfortunately it does not seem like the internal build has solved this issue.

I am changing the read URL with the following method:

function refreshGrid() {
    $grid.data("kendoGrid").dataSource.transport.options.read.url = getEndpoint();
    $grid.data("kendoGrid").dataSource.read();
}

Whereby getEndpoint() returns the full URI based on some state parameters.

The grid is initially setup with the following configuration.

dataSource: {
    type: "odata",
    transport: {
        read: {
            dataType: "json",
        },
    },
    schema: {
        data: function(data) { return data.Items; },
        total: function(data) { return data.Count; }
    },
    pageSize: 20,
    serverPaging: true,
    serverFiltering: true,
    serverSorting: true,
},

And refreshGrid() is called almost straight away after the grid is initialised. Given the interaction of 1. First page load and 2. Clicking export results in the following HTTP calls being made.

GET http://testdataservice.local/api/collection?inlinecount=allpages&%24top=20 200 OK
GET http://localhost:31337/collection?%24inlinecount=allpages&%24top=21 200 OK 

Regards
0
Accepted
Atanas Korchev
Telerik team
answered on 24 Dec 2014, 07:49 AM
Hi,

The excel export creates a new data source using the options of the grid's data source. This is why it can't get the new url. I recommend one of the following:

1. Assign the new URL to dataSource.options.transport.read as well

$grid.data("kendoGrid").dataSource.transport.options.read.url = getEndpoint();
 
$grid.data("kendoGrid").dataSource.options.transport.read.url = getEndpoint();

2. Or specify the url option of the data source as a function:


dataSource: {
   transport: {
      read: {
         url: getEndpoint
      }
   }
}

Regards,
Atanas Korchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Greg
Top achievements
Rank 1
answered on 07 Jan 2015, 05:16 PM
Hi,

Happy new year!

Setting the options.transport.read.url worked fine. I was unaware of that options attribute, might have missed it in the documentation however.

Thank you for your help! :-)
Tags
Grid
Asked by
Greg
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Greg
Top achievements
Rank 1
Share this question
or