Anand Singh
Anand Singh

Reputation: 327

How to export extjs grid data to excel?

I have a grid with large number of records. I use filters to filter the data as required. But i want to export the filtered data to a excel sheet for further usage.

I went through some articles available but they seem different and not compatible with latest 4.2 version.

Please help me in achieving this in simple manner.

Thanks much!

Upvotes: 9

Views: 22476

Answers (3)

Zon
Zon

Reputation: 19880

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

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

  3. Add "grid" parameter to all functions starting with the entry one (downloadExcelXml()).

  4. Replace the remaining "this" calls to grid references (as functions were expected to act inside a grid).

  5. Now add this button in your grid constructor and call downloadExcelXml() as a handler like this:

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

Upvotes: 3

JJR
JJR

Reputation: 773

As far as I know this isn't possible without a Serverside implementation in a cross browser manner.

In theory you create a OpenXML document string by reading the current records from the store and encode it with base64. Then write this to a Data Uri. The first that didn't allow inline data other then images is IE so this won't work for all IE browser version due to limitations like size and images only. This will be the reason why there are no up to date implementations.

Upvotes: 3

Related Questions