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

vue 3 Grid Excel Export from DataSource

1 Answer 264 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrea
Top achievements
Rank 1
Andrea asked on 03 Mar 2021, 03:49 PM

Hello there!

Many examples show how to export data from the grid, specifically using the saveExcel method, using local data.  How do you do it using a remote DataScource?

1 Answer, 1 is accepted

Sort by
0
Petar
Telerik team
answered on 05 Mar 2021, 11:15 AM

Hi Andrea,

I've used this example from our demos as a basis to implement this StackBlitz project

The example has the following function that is executed when the "Export Excel" button is clicked. 

exportExcel() {
  var that = this;

  fetch(
    "https://demos.telerik.com/kendo-ui/service-v4/odata/Orders?$count=true&$skip=0",
    this.init
  )
    .then(response => response.json())
    .then(json => {
      that.requestInProgress = false;

      const total = json["@odata.count"];
      const data = json["value"];
      const orders = new Array(total).fill().map((e, i) => ({ Index: i }));

      data.forEach((order, i) => {
        orders[i] = { Index: i, ...order };
      });

      saveExcel({
        data: orders,
        fileName: "myFile",
        columns: [
          { field: "Index" },
          { field: "OrderID", title: "Order ID" },
          { field: "ShipCountry", title: "Ship Country" },
          { field: "ShipName", title: "Ship Name" }
        ]
      });
    });
}

What e do with the above implementation is to fetch all data available in the remote datasource, store it in a variable and then export this data to an Excel file. 

Check the provided example and let me know if you have any questions about the provided implementation.

Regards,
Petar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Andrea
Top achievements
Rank 1
Answers by
Petar
Telerik team
Share this question
or