Export of grouped rows to Excel, pdf, html and csv

ShipCountry
Customer Name
Freight
Shipping Via
Shipped Date
Shipping City
 
 
 
 
 
 
No rows to display.
Loading...

95
 
1
2
    $(function () {
3
        var colM = [
4
            { title: "ShipCountry", width: 120, dataIndx: "ShipCountry" },
5
            { title: "Customer Name", width: 130, dataIndx: "ContactName" },
6
            {
7
                title: "Freight", width: 120, format: '$##,###.00',
8
                summary: {
9
                    type: "sum"
10
                },
11
                dataType: "float", dataIndx: "Freight"
12
            },
13
            { title: "Shipping Via", width: 130, dataIndx: "ShipVia" },
14
            { title: "Shipped Date", width: 100, dataIndx: "ShippedDate", dataType: "date", format: 'yy-mm-dd' },
15
            //{ title: "Shipping Address", width: 220, dataIndx: "ShipAddress" },
16
            { title: "Shipping City", width: 130, dataIndx: "ShipCity" }
17
        ];
18
        var dataModel = {
19
            location: "remote",
20
            dataType: "JSON",
21
            method: "GET",
22
            url: "/Content/orders.json"
23
            //url: "/pro/orders/get",//for ASP.NET
24
            //url: "orders.php",//for PHP
25
        };
26
        var groupModel = {
27
            on: true,
28
            dataIndx: ['ShipCountry'],
29
            collapsed: [false],
30
            title: [
31
                "{0} ({1})",
32
                "{0} - {1}"
33
            ]
34
        };
35
        var obj = {
36
            height: 500,
37
            toolbar: {
38
                items: [
39
                {
40
                    type: 'select',
41
                    label: 'Format: ',
42
                    cls: 'export-format',
43
                    options: [{ xlsx: 'Excel', csv: 'Csv', htm: 'Html', pdf: 'PDF' }]
44
                },
45
                {
46
                    type: 'button',
47
                    label: "Export",
48
                    icon: 'ui-icon-arrowthickstop-1-s',
49
                    listener: function () {
50
51
                        var format = this.toolbar().find('.export-format').val(),
52
                            data = this.exportData({
53
                                format: format,
54
                                render: true
55
                            });
56
                        if (format == 'pdf') {
57
                            var dd = {
58
                                footer: function (currentPage, pageCount) { return currentPage.toString() + ' of ' + pageCount; },
59
                                pageOrientation: 'landscape',
60
                                content: [
61
                                    {
62
                                        //include document definition of grid.
63
                                        table: data
64
                                    }
65
                                ]
66
                            };
67
                            pq.getScripts(['/pdfmake027/pdfmake.min.js', '/pdfmake027/vfs_fonts.min.js'], function () {
68
                                //finally open the pdf file.
69
                                pdfMake.createPdf(dd).open();
70
                            });
71
                        }
72
                        else {
73
                            pq.saveAs(data, "pqGrid." + format);
74
                        }
75
                    }
76
                }]
77
            },
78
            dataModel: dataModel,
79
            scrollModel: { autoFit: true },
80
            colModel: colM,
81
            numberCell: { show: false },
82
            menuIcon: true,
83
            selectionModel: { type: 'cell' },
84
            groupModel: groupModel,
85
            title: 'Group Rows',
86
            showTitle: false,
87
            resizable: true,
88
            hwrap: false,
89
            wrap: false
90
        };
91
        var grid = pq.grid("#grid_export", obj);
92
93
    });
94
95
ParamQuery Pro Eval