7
votes

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!

3
What you had tried so far??Hariharan

3 Answers

3
votes

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.

3
votes

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
      }
    };