How to export extjs grid data to excel?

I have a grid with a lot of records. I use filters to filter data as needed. But I want to export the filtered data to an excel sheet for future use.

I looked through some available articles, but they seem different and are not compatible with the latest version 4.2.

Please help me achieve this in a simple way.

Thanks a lot!

+6
source share
3 answers

As far as I know, this is not possible without the implementation of Serverside in the browser.

In theory, you create an OpenXML string by reading the current records from the repository and encoding it with base64.Then write it to Data Uri . The first one that did not allow embedded data other than images is IE, so this will not work for all versions of IE browser due to limitations such as size and images. This will cause a lack of modern implementations.

+3
source

Successfully implemented this approach for Ext JS 4. To give it the flexibility of an abstract class, follow the instructions:

  • Take the functions from here and extract them into a separate class as global.
  • Replace all references to "this" with global function calls.

  • Add the grid parameter to all functions, starting with input (DownloadExcelXml ()).

  • Replace the remaining "this" calls with references to the grid (since the functions had to act inside the grid).

  • Now add this button to your grid constructor and call downloadExcelXml () as a handler as follows:

     exportButton = { xtype: 'button', text: 'xls', listeners: { click: function (button, event, eOpts) { downloadExcelXml( false, "TableHeader", eOpts.data.grid); }, data: { grid: this } }; 
+2
source

Source: https://habr.com/ru/post/949710/


All Articles