1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    219
    Answers
    13
    Vote Rating
    9
    dedoz will become famous soon enough

      0  

    Default Unanswered: export store records to excel

    Unanswered: export store records to excel


    Hi, i need some advice on how to do this or where to look in the documentation.
    In general is export Ext store records to excel, using a server side code to generate the excel and retrieve that file, as a link or as http response using excel headers.

    Im using Ext.Direct as proxy for all my stores/models.

    using store.load() the http request send some parameters as JSON to the server (like page, limit, filter, sorts, etc)
    in some point i want to export this store, to excel.

    In the server side i have a code that receives all params as a normal store.load() but instead of returning the JSON records, generates an excel.

    My problem is how to call this excel method and pass all the params store.load() sends.

    Cant do it using with something like store.load({params:{export: true}}) even when the server will understand that he needs to export to excel instead of generating json, store.load() expects a json response, not an excel.

    I need something like
    - get all the params store.load() will send to the server to load those record.
    - send a request using another mechanism like a form ? dunno im lost here. something that sends those params as JSON but doesnt expect a JSON as http response.

    anyone can help me on this ? or some similar solution to export to excel
    Note that all my store/models load records correctly and i excecute manually that server side excel generator, works properly, just need a way to call him from ext and pass him the params store.load used to load his records.

    (sorry for my bad english)

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,884
    Answers
    653
    Vote Rating
    440
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    I have used this on server side:
    http://phpexcel.codeplex.com/

    I see there is the following for client side:
    http://www.sencha.com/forum/showthread.php?136598

    Regards,
    Scott.

  3. #3
    Sencha User
    Join Date
    Dec 2011
    Posts
    219
    Answers
    13
    Vote Rating
    9
    dedoz will become famous soon enough

      0  

    Default


    thanks for your answer.
    im using http://phpexcel.codeplex.com/
    the problem is not how to generate excels in server side,
    is how to send http request that is send by store.load without using store.load since it expects a json response.

    i need all those params store.load used to load its records, to tell the server side export to execute the same query and put those records on a excel.

  4. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,884
    Answers
    653
    Vote Rating
    440
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    I usually send an ajax request with parameters to create the XLS

    Code:
    Ext.Ajax.request({
        method: 'POST',
        url: 'export_table',
        params: {
            report_params: report_params,
        },
        success: function(xhr) {
            // clear mask and display
            grid_panel.getEl().unmask();
            window.open('xls/' + employee_report_name + '.xls');
        },
        failure: function() {
            // clear mask
            grid_panel.getEl().unmask();
            alert('AJAX ERROR: Unable to export report, please contact support');
        }
    });
    Regards,
    Scott.

  5. #5
    Sencha User
    Join Date
    Dec 2011
    Posts
    219
    Answers
    13
    Vote Rating
    9
    dedoz will become famous soon enough

      0  

    Default


    thanks alot.
    missing one thing, the report_params.
    for me, as im trying to export records from store, i need to get what store.load sends as http request (the JSON) those are my report_params in your code.
    its possible to get the json request that a store.load sends to the server ? to pass those same params as report_params ?
    thats my problem.

  6. #6
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,884
    Answers
    653
    Vote Rating
    440
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    Are you sure? .. the entire benefit of using a server based report is not waiting on the transfer of data over the pipe to get the report.

    You would use the same parameters that were used to populate the grid data in the first place and specify that information as a param to the php reports to generate SQL for the report.

    You want to send all of the data back from the grid to the report? You can use Ext.Encode() to send your data back if you must.

    Scott.

  7. #7
    Sencha User
    Join Date
    Dec 2011
    Posts
    219
    Answers
    13
    Vote Rating
    9
    dedoz will become famous soon enough

      0  

    Default


    no i dont want to send the records, i want to send the params that store.load used to load those records,
    is not just my own params, it also sends page, limit, sorters, filters, etc, all that makes the JSON request to retrieve those records.
    i need to give all those params to my export method so he can reproduce the query, get the records (all this on server side) and produce the excel.

    anyway already doing this with something like, havent tested
    Code:
    getLoadParams : function(store)
        {    var options = {};
            
            options.filters = store.filters.items;
            options.sorters = store.getSorters();
            options.groupers = store.groupers.items;
            options.page = store.currentPage;
            options.start = (store.currentPage - 1) * store.pageSize;
            options.limit = store.pageSize;
            
            Ext.apply(options,store.getProxy().extraParams);
            return options;
        }
    missing the method and the action of the proxy api (im using ExtDirect) havent figure how to get those params, then ill have all the params that store.load used to get its records.

    then i can pass this options as report_params in your example.
    my english fails

    btw your code been really usefull for this, kind of using the same no copyrights

Thread Participants: 1