In the below example, grid data is sorted via remote request.

Grid sends pq_sort parameter to the remote server as mentioned in the tutorial on remote requests.

 
ShipCountry
Customer Name
Shipping Via
Order ID
Order Date
Required Date
Shipped Date
Freight
Shipping Name
Shipping Address
Shipping City
 
 
 
 
 
 
 
 
 
 
 
 
No rows to display.
Loading...


76
 
1
2
    $(function () {
3
        var colM = [
4
            { title: "ShipCountry", width: 100, dataIndx: "ShipCountry" },
5
            { title: "Customer Name", width: 130, dataIndx: "ContactName" },
6
            { title: "Shipping Via", width: 100, dataIndx: "ShipVia" },
7
            { title: "Order ID", width: 100, dataIndx: "OrderID", dataType: "integer" },
8
            { title: "Order Date", width: "100", dataIndx: "OrderDate", dataType: "date" },
9
            { title: "Required Date", width: 100, dataIndx: "RequiredDate", dataType: "date" },
10
            { title: "Shipped Date", width: 100, dataIndx: "ShippedDate", dataType: "date" },       
11
            { title: "Freight", width: 100, align: "right", dataType: "float", dataIndx: "Freight" },
12
            { title: "Shipping Name", width: 160, dataIndx: "ShipName" },
13
            { title: "Shipping Address", width: 200, dataIndx: "ShipAddress" },
14
            { title: "Shipping City", width: 100, dataIndx: "ShipCity" },
15
            { title: "Shipping Region", width: 130, dataIndx: "ShipRegion" },
16
            { title: "Shipping Postal Code", width: 135, dataIndx: "ShipPostalCode" }
17
        ];
18
        var dataModel = {
19
            location: "remote",                        
20
            method: "GET",
21
            url: "/pro/orders/get" //for ASP.NET
22
            //url: "orders.php", //for PHP
23
        }
24
25
        var gObj = {            
26
            dataModel: dataModel,
27
            sortModel: {
28
                type: 'remote',
29
                single: false,
30
                sorter: [{ dataIndx: 'ShipCountry', dir: 'up' }, { dataIndx: 'ContactName', dir: 'down'}],
31
                space: true,
32
                multiKey: null
33
            },
34
            flex: {one: true},
35
            wrap: false,
36
            hwrap: false,            
37
            showTitle: false,
38
            colModel: colM,            
39
            resizable: true,            
40
            virtualX: true, virtualY: true,
41
            freezeCols: 2,
42
            toolbar: {
43
                items: [
44
                    {
45
                        type: 'select',
46
                        label: 'Sorting Type:',
47
                        value: 'multi', //default value.
48
                        options: [
49
                            {'single': 'Single without shift key'},
50
                            {'singlemulti': 'Single with shift key for multiple'},
51
                            {'multi': 'Multiple columns'}
52
                        ],
53
                        listener: function(evt){                            
54
                            var val = $(evt.target).val(),
55
                                single = true,
56
                                multiKey = null;
57
58
                            if(val == 'singlemulti'){                                
59
                                multiKey = 'shiftKey';
60
                            }
61
                            else if(val == 'multi'){
62
                                single = false;
63
                            }    
64
65
                            this.option("sortModel.single", single);
66
                            this.option("sortModel.multiKey", multiKey);
67
                            this.sort(); //refresh sorting.                        
68
                        }
69
                    }
70
                ]
71
            }
72
        };
73
        var $grid = $("#grid_sorting_remote").pqGrid(gObj);
74
75
    });
76