Author Topic: How to Export Local Data  (Read 2496 times)

Hidehiro Ishii

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 44
    • View Profile
How to Export Local Data
« on: June 08, 2018, 10:52:48 am »
Hi Team,

I want to grid data locally without round trip to remote server.
So I have used a newest version of FileSaver.js(2018-03-22) with a sample code which is on your site(Demo Name is Local Export).
But it does NOT work correctly.
And then I have changed a old version of FileSaver.js(2014-01-24),is does work correctly.
Please let me know how to use a newest version of FileSaver.js with your sample code as follows.

    $(function () {
        function fillOptions(grid) {
            var column = grid.getColumn({ dataIndx: 'ShipCountry' });
            column.filter.options = grid.getData({ dataIndx: ['ShipCountry'] });
            column.filter.cache = null;
            grid.refreshHeader();
        }
        var colM = [
            { title: "ShipCountry", width: 120, dataIndx: "ShipCountry",
                filter: {
                    type: 'select',
                    prepend: { '': 'All Countries' },
                    valueIndx: 'ShipCountry',
                    labelIndx: 'ShipCountry',
                    condition: 'equal',
                    listeners: ['change']
                }
            },
            { title: "Customer Name", width: 130, dataIndx: "ContactName" },
            { title: "Freight", width: 120, format: '$##,###.00',
                summary: {
                    type: "sum"
                },
                dataType: "float", dataIndx: "Freight"
            },
            { title: "Shipping Via", width: 130, dataIndx: "ShipVia" },
          //{ title: "Shipped Date", width: 100, dataIndx: "ShippedDate", dataType: "date" },
            { title: "Shipping Address", width: 220, dataIndx: "ShipAddress" },
            { title: "Shipping City", width: 130, dataIndx: "ShipCity" }
      ];
        var dataModel = {
            location: "remote",
            dataType: "JSON",
            method: "GET",
            url: "/Content/orders.json"
            //url: "/pro/orders/get",//for ASP.NET
            //url: "orders.php",//for PHP
        };
        var groupModel = {
            on: true,
            dataIndx: ['ShipCountry'],
            showSummary: [true],
            grandSummary: true,
            collapsed: [false],
            title: [
                "{0} ({1})",
                "{0} - {1}"
            ]
        };
        var obj = {
            height: 500,
            toolbar: {
                items: [
                {
                    type: 'select',
                    label: 'Format: ',               
                    attr: 'id="export_format"',
                    options: [{ xlsx: 'Excel', csv: 'Csv', htm: 'Html', json: 'Json'}]
                },
                {
                    type: 'button',
                    label: "Export",
                    icon: 'ui-icon-arrowthickstop-1-s',
                    listener: function () {

                        var format = $("#export_format").val(),                           
                            blob = this.exportData({
                                //url: "/pro/demos/exportData",
                                format: format,                               
                                render: true
                            });
                        if(typeof blob === "string"){                           
                            blob = new Blob([blob]);
                        }
                        saveAs(blob, "pqGrid."+ format );
                    }
                }]
            },
            dataModel: dataModel,
            scrollModel: { autoFit: true },
            colModel: colM,
            numberCell: { show: false },
            filterModel: { on: true, header: true, type: "local" },
            selectionModel: { type: 'cell' },
            groupModel: groupModel,
            load: function (evt, ui) {
                //options for ShipCountry filter.   
                fillOptions(grid);
            },
            showTitle: false,
            resizable: true,
            virtualX: true,
            virtualY: true,
            hwrap: false,
            wrap: false
        };
        var grid = pq.grid("#grid_export", obj);

    });

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6260
    • View Profile
Re: How to Export Local Data
« Reply #1 on: June 11, 2018, 12:35:59 pm »
It's because FileSaver.js included with v1.3.8 doesn't load directly in the browser; it has export keyword.

Please follow the instructions here to obtain dist version of the files:

https://github.com/eligrey/FileSaver.js/issues/431

Hidehiro Ishii

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: How to Export Local Data
« Reply #2 on: June 12, 2018, 01:30:11 pm »
Hi. Team,

Thank you for your reply.
I think it is NOT easy to use the version 1.3.8 with my environment.
So I have decided to use the version 1.3.2.
By the way, I want to open savefile dialog when I export file with FileSaver.
Because I want to select folder to save file and to change file name.
Can I do it ?