1. #1
    Sencha User
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    65
    Vote Rating
    0
    duskandawn is on a distinguished road

      0  

    Question Export to Excel from server side

    Export to Excel from server side


    Hello All,
    I am trying to get the Export to Excel functionality work from the server side.
    I already have the servlet which writes the response data, with the correct header for excel.
    But when i make an Ajax request with my grid data on to this servlet, i do not see the save dialogue poping up.

    I tried using the isUpload:true, option in my request but still no luck.
    PHP Code:
    function buildRPC2(request){
        var 
    extRequest = {
            
    url '../TestRequest',
            
    method'POST',
            
    isUpload true
        
    };
        return 
    extRequest;
    }

    exportTOExcel: function (){
                var 
    grid Ext.getCmp('gridRegion');
                var 
    updatedNewRecs = [];
                
    grid.getStore().each(function(rec){
                      
    updatedNewRecs.push(rec.data);
                });
                
    Ext.Ajax.request(buildRPC2(({
                   
    data updatedNewRecs
                         
                
    })));
    }, 
    I am setting correct headers required for the excel. But no luck.
    I read somewhat about the hidden iframe trick, but cannot visualize fully in terms with ExtJS and how to set it up

    If that is the only solution, can someone please shed some more light on that technique.

    Thank you,

  2. #2
    Sencha User ashaihullin's Avatar
    Join Date
    Jan 2010
    Location
    Kyrgyzstan, Bishkek
    Posts
    67
    Vote Rating
    0
    ashaihullin is on a distinguished road

      0  

    Default


    add this to body:
    Code:
    <iframe type="hidden" src="" style="display:none;" id="downloadFrame"></iframe>
    then:
    Code:
    var nav = document.getElementById("downloadFrame");
    nav.src = 'http://bla.com/TestRequest?params';

  3. #3
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,505
    Vote Rating
    52
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Does Ext.Ajax.request have a data option?

    When you examine that request in Firebug, what gets sent to the server?

  4. #4
    Sencha User
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    65
    Vote Rating
    0
    duskandawn is on a distinguished road

      0  

    Default


    I missed posting full code for my builRPC method.
    Looks like :
    PHP Code:
    function buildRPC2(request){
        var 
    extRequest = {
            
    url '../TestRequest',
            
    method'POST',
            
    isUpload true
        
    };
           if (
    request.data){
                  
    extRequest.jsonData Ext.encode(request.data);
        }
        return 
    extRequest;

    I do see data being sent on to server.
    But cant find a way to get the save dialog for excel.
    Even with iframe approach how do i pass the whole grid data to the server, Passing data in the request query may be limited.

    Please advise,

  5. #5
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,505
    Vote Rating
    52
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    You cannot download with Ajax. You must submit a form. You must have a hidden form element, and submit that using the Ext.Ajax.request form option.

    The server must set the Content-Disposition header.

    To be doing this kind of work you MUST be familiar with the HTTP protocol.

    http://www.w3.org/Protocols/rfc2616/...html#sec19.5.1

  6. #6
    Sencha User
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    65
    Vote Rating
    0
    duskandawn is on a distinguished road

      0  

    Default


    Works perfect now, thanks so much

Similar Threads

  1. Export Excel, please help
    By pietromenea in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 3 Aug 2010, 8:19 AM
  2. export to Excel
    By FMIC_DEV in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 29 Jan 2008, 8:42 AM
  3. export excel
    By neenhouse in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 20 Dec 2007, 4:35 PM
  4. Excel CSV as new url for server side script
    By jdaum in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 9 Jul 2007, 2:22 PM

Thread Participants: 2