Results 1 to 8 of 8

Thread: How do you get all store parameters? (4.1)

  1. #1
    Sencha User
    Join Date
    Aug 2011
    Posts
    130
    Answers
    4

    Default Answered: How do you get all store parameters? (4.1)

    How I'll get all the parameters that will be send when store.load() is run? I mean, I will not run store.load() but I want to get all request parameters. How I'll do it? (This is a grid's store)

  2. Here is the solution
    PHP Code:
            buttons : [
            {
                
    text LANG.EXCEL__GETIR// Getir
                // href: '/application.php?way=departmanTan&case=fetchNew' + '&excel=1',
                // hrefTarget: '_blank' // used in 4.1
                
    handler: function() {
                    var 
    form Ext.fly('exportXLSForm');
                    if(!
    form)
                    {
                        var 
    frm document.createElement('form');
                        
    frm.id 'exportXLSForm';
                        
    frm.name 'excelForm'// id
                        
    frm.className 'x-hidden';
                        
    document.body.appendChild(frm);
                        
    form Ext.fly('exportXLSForm');
                    }
                    
    //console.log(grid.filters.getFilterData());
                    
                    
                    
                    
    departments  grid.filters.getFilterData();
                    var 
    department;
                    for (var 
    0len departments.lengthleni++) {
                        
    obj departments[i];
                        for (var 
    key in obj) {
                            if (
    key !== 'data' && obj.data) {
                                
    obj.data[key] = obj[key];
                            }
                        }
                        
    departments[i] = obj.data || obj;
                    }
                    
    // console.log(departments);
                    //console.log(departments);
                    //console.log(JSON.stringify(departments));
                    // console.log(grid);
                    //console.log(JSON.stringify(grid.filters.getFilterData()));
                    
    tempFilter = {};
                    
    //console.log(tempFilter);
                    //bilmemne = JSON.stringify(tempFilter)
                    //console.log(bilmemne); 
                    // console.log(grid.store.sorters.items[0]);
                    
    params = {};
                    
    params.filter JSON.stringify(departments);
                    
    sorter = {};
                    
    sorter.property grid.store.sorters.items[0].property;
                    
    sorter.direction grid.store.sorters.items[0].direction;
                    
    tempJson JSON.stringify(sorter);
                    
    params.sort '[' tempJson ']';
                    
    params.excel true;
                    
    Ext.Ajax.request(
                    {
                        
    url '/application.php?way=departmanTan&case=fetchNew',
                        
    method 'POST',
                        
    form form,
                        
    params params,
                        
    isUpload true
                    
    });
                }
            },
            {
                
    text LANG.CANCEL// ?ptal
                
    handler : function()
                {
                    
    excelWindow.close();
                }
            }], 
    Especially the grid.filters.getFilterData() and
    sorter.property = grid.store.sorters.items[0].property;
    sorter.direction = grid.store.sorters.items[0].direction;

  3. #2
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,791
    Answers
    585

    Default

    Could you elaborate a little on what it is you're trying to do exactly? What's the underlying problem you're trying to solve?

  4. #3
    Sencha User
    Join Date
    Aug 2011
    Posts
    130
    Answers
    4

    Default

    I'll use them to download Excel file.

  5. #4
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,791
    Answers
    585

    Default

    If I understand correctly, you have a grid and want to give your users the option to download it as a spreadsheet? To do this, you want to make an (almost) identical request to the server as the request used to load the grid's store.

    This could prove quite tricky, especially if you're using filters that are added in beforeload. One way to do it would be to add a temporary beforeload listener that captures the parameters then cancels the load. However, it seems a little risky to rely on the order the beforeload listeners will fire.

    Another way that might work is to pull a temporary switch on the store's proxy. Put in a custom proxy that captures the parameters then switch it back to the original proxy.

    Will the store have already loaded using the same set of options? If it will, it might be possible to capture the options on that request with a suitable hook and then you've got them for the download request.

  6. #5
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,410
    Answers
    716

    Default

    Do you want to create a XLS from the store, or download an existing XLS based on params?

    Scott.

  7. #6
    Sencha User
    Join Date
    Aug 2011
    Posts
    130
    Answers
    4

    Default

    Quote Originally Posted by scottmartin View Post
    Do you want to create a XLS from the store, or download an existing XLS based on params?

    Scott.
    I want to download server side generated XLSX based on parameters.

  8. #7
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,410
    Answers
    716

    Default

    You should be able to use ajax to make a request to the server and return the file

    Code:
    Ext.Ajax.request({
        method: 'POST',
        url: 'index.php/table_export/export_table/',
        params  : {
            report_name:   employee_report_name,
            report_table: 'viewEmployees',
            report_param:  employee_report_param,
            report_order:  sortOrder // compound string for JAVA parameter
        },
        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');
        }
    });
    // example server return
    Code:
    //create xls
    $objWriter = IOFactory::createWriter($objPHPExcel, 'Excel5');
    
     // Sending headers to force the user to download the file
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: inline;attachment;filename="'.$reports_array['report_name'].'.xls"');
    
    $objWriter->save('xls/'.$reports_array['report_name'].'.xls');
    
    echo "{success:true}"; // done.. return

    Your server will of course, need to handle the parameters sent to find the file.

    Scott.

  9. #8
    Sencha User
    Join Date
    Aug 2011
    Posts
    130
    Answers
    4

    Default

    Here is the solution
    PHP Code:
            buttons : [
            {
                
    text LANG.EXCEL__GETIR// Getir
                // href: '/application.php?way=departmanTan&case=fetchNew' + '&excel=1',
                // hrefTarget: '_blank' // used in 4.1
                
    handler: function() {
                    var 
    form Ext.fly('exportXLSForm');
                    if(!
    form)
                    {
                        var 
    frm document.createElement('form');
                        
    frm.id 'exportXLSForm';
                        
    frm.name 'excelForm'// id
                        
    frm.className 'x-hidden';
                        
    document.body.appendChild(frm);
                        
    form Ext.fly('exportXLSForm');
                    }
                    
    //console.log(grid.filters.getFilterData());
                    
                    
                    
                    
    departments  grid.filters.getFilterData();
                    var 
    department;
                    for (var 
    0len departments.lengthleni++) {
                        
    obj departments[i];
                        for (var 
    key in obj) {
                            if (
    key !== 'data' && obj.data) {
                                
    obj.data[key] = obj[key];
                            }
                        }
                        
    departments[i] = obj.data || obj;
                    }
                    
    // console.log(departments);
                    //console.log(departments);
                    //console.log(JSON.stringify(departments));
                    // console.log(grid);
                    //console.log(JSON.stringify(grid.filters.getFilterData()));
                    
    tempFilter = {};
                    
    //console.log(tempFilter);
                    //bilmemne = JSON.stringify(tempFilter)
                    //console.log(bilmemne); 
                    // console.log(grid.store.sorters.items[0]);
                    
    params = {};
                    
    params.filter JSON.stringify(departments);
                    
    sorter = {};
                    
    sorter.property grid.store.sorters.items[0].property;
                    
    sorter.direction grid.store.sorters.items[0].direction;
                    
    tempJson JSON.stringify(sorter);
                    
    params.sort '[' tempJson ']';
                    
    params.excel true;
                    
    Ext.Ajax.request(
                    {
                        
    url '/application.php?way=departmanTan&case=fetchNew',
                        
    method 'POST',
                        
    form form,
                        
    params params,
                        
    isUpload true
                    
    });
                }
            },
            {
                
    text LANG.CANCEL// ?ptal
                
    handler : function()
                {
                    
    excelWindow.close();
                }
            }], 
    Especially the grid.filters.getFilterData() and
    sorter.property = grid.store.sorters.items[0].property;
    sorter.direction = grid.store.sorters.items[0].direction;

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •