[CLOSED] Export store data to Excel using HttpProxy

Page 2 of 2 FirstFirst 12
  1. #11
    Quote Originally Posted by Daniil View Post
    Here is the full code:
    var store = GridPanel1.getStore(),
    
        options = store.lastOptions || {},
        pn = store.paramNames;
     
    GridPanel1.filters.onBeforeLoad(store, options);
     
    options.params[pn.sort] = store.sortInfo.field;
    options.params[pn.dir] = store.sortInfo.direction;
    
    store.beforeLoadParams(store, options);
    
    alert(Ext.encode(options));
    Is the above code equivalent with the grid.store.getSortState, grid.getColumnModel().getColumnsBy and grid.getFilterPlugin()

    I am using this old approach to get settings/options from the grid and your code is so much cleaner :-)
                var settings = { 
                    sortState:{},
                    columns:[],
                    filter: []
                    };
                
                // Get any custom sorting from the grid
                settings.sortState = grid.store.getSortState() || {field:"", direction:""};
                
                // Get column state from the grid
                grid.getColumnModel().getColumnsBy( function(c) {
                    settings.columns.push(
                            {
                                id: c.id, 
                                dataIndex: c.dataIndex, 
                                columnWidth: c.columnWidth,
                                hidden: c.hidden, 
                                locked: c.locked 
                                }
                            );
                        }
                    );
                
                // Any custom filters applied
                if (grid.getFilterPlugin() != null) {
                    grid.getFilterPlugin().filters.each(function(f) {
                        if (f.active) {
                            settings.filter.push({ field: f.dataIndex, args: f.serialize() });
                            }
                        });
                    }
                
                // Get which format to use for data export
                if (format == 'sel')
                {
                    switch (btnExport.activeItem.id)
                    {
                        case 'mnuExportToXLS':
                            format = 'xls';
                            break;
    
                        case 'mnuExportToXML':
                            format = 'xml';
                            break;
    
                        case 'mnuExportToCSV':
                            format = 'csv';
                            break;
    
                        case 'mnuExportToPDF':
                            format = 'pdf';
                            break;
    
                         default:
                            break;
                    }
                }
    
                // Use httphandler to download/get the export
                window.location = 'genericGet.ashx' +
                    '?table=' + table + 
                    '&format=' + format +
                    '&filter=' + txtFilter.getValue() +
                    '&settings=' + Ext.encode({settings:[settings]});
    thanks /Peter
  2. #12
    Hi @plykkegaard,

    There is no info about columns in my code.

    Also your code to get sort state is good.

    I think you could simplify only getting the filters info if you'd look into the GridFilters sources.

    Probably, you could use the getFilterValues method.

    getFilterValues method
    getFilterValues: function () {
        var filters = [];
    
        this.filters.each(function (f) {
            if (f.active) {
                filters.push({ field: f.dataIndex, value: f.getValue() });
            }
        });
    
        return filters;
    }
    So, you should be able to replace your code with:
    settings.filter = grid.filters.getFilterValues();
  3. #13
    Quote Originally Posted by Daniil View Post
    So, you should be able to replace your code with:
    settings.filter = grid.filters.getFilterValues();
    Ahh yes - thanks
    Sorry for hijacking ;-)

    rgds /Peter
Page 2 of 2 FirstFirst 12

Similar Threads

  1. Export grid panel data to excel
    By sumesh in forum 1.x Help
    Replies: 1
    Last Post: Sep 23, 2013, 9:07 AM
  2. Replies: 1
    Last Post: May 28, 2012, 5:17 AM
  3. Export grid panel data to excel
    By sumesh in forum 1.x Help
    Replies: 0
    Last Post: May 19, 2012, 6:01 AM
  4. Export data to excel - in order columns
    By tanju_yayak in forum 1.x Help
    Replies: 2
    Last Post: Mar 22, 2012, 6:40 AM
  5. Data Export Excel Column Names
    By BLOZZY in forum 1.x Help
    Replies: 0
    Last Post: Feb 02, 2012, 2:02 PM

Tags for this Thread

Posting Permissions