source: ether_statistics/web/resources/js/Wijmo.2.2.2/Wijmo-Complete/development-bundle/samples/grid/maintain-selection-sorting-state.html @ 626

Last change on this file since 626 was 626, checked in by vmipsl, 12 years ago

wijmo

File size: 5.5 KB
Line 
1<!doctype html>
2<html lang="en">
3<head>
4    <title>Grid - Sorting</title>
5    <meta charset="utf-8" />
6    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
7    <meta name="description" content="wijgrid provides sorting feature" />
8    <meta name="keywords" content="" />
9    <meta name="author" content="ComponentOne" />
10   
11    <link href="../../themes/rocket/jquery-wijmo.css" rel="stylesheet" type="text/css" />
12    <link href="../../themes/wijmo/jquery.wijmo-open.2.2.2.css" rel="stylesheet" type="text/css" />
13    <link href="../../themes/wijmo/jquery.wijmo.wijgrid.css" rel="stylesheet" type="text/css" />
14
15    <script src="../../external/jquery-1.8.0.min.js" type="text/javascript"></script>
16    <script src="../../external/jquery-ui-1.8.23.custom.min.js" type="text/javascript"></script>
17    <script src="../../external/globalize.min.js" type="text/javascript"></script>
18    <script src="../../external/jquery.mousewheel.min.js" type="text/javascript"></script>
19    <script src="../explore/js/jquery.cookie.js" type="text/javascript"></script>
20
21    <script src="../../external/jquery.wijmo-open.all.2.2.2.min.js" type="text/javascript"></script>
22    <script src="../../wijmo/jquery.wijmo.wijdatasource.js" type="text/javascript"></script>
23    <script src="../../wijmo/jquery.wijmo.wijgrid.js" type="text/javascript"></script>
24
25    <script id="scriptInit" type="text/javascript">
26        $(document).ready(function () {
27
28            var selectionRestored = false,
29                $grid = $("#demo");
30
31            $grid.wijgrid({
32                allowSorting: true,
33                selectionMode: "multiRange",
34                columns: restoreSort([ { uid: "col0" }, { uid: "col1" }, { uid: "col2" } ]),
35
36                sorted: function (e, args) {
37                    $.cookie("sortUID", args.column.uid.toString());
38                    $.cookie("sortDirection", args.column.sortDirection.toString());
39                },
40
41               selectionChanged: function (e, args) {
42                   if (selectionRestored || !$.cookie("selectedCells")) {
43                       storeSelection($grid.wijgrid("selection").selectedCells());
44                   }
45               }
46            });
47
48            restoreSelection($grid);
49
50            function restoreSort(columns) {
51                var result = columns,
52                    uid = $.cookie("sortUID");
53
54                if (uid) {
55                    $.each(columns, function (index, item) {
56                        if (item.uid === uid) {
57                            item.sortDirection = $.cookie("sortDirection");
58                        }
59                    });
60                }
61
62                return result;
63            }
64
65            function storeSelection(selectedCells) {
66                var result = "", i, len, cell;
67
68                for (i = 0, len = selectedCells.length(); i < len; i++) {
69                    cell = selectedCells.item(i);
70                    result += cell.cellIndex() + ":" + cell.rowIndex() + " ";
71                }
72
73                $.cookie("selectedCells", result);
74            }
75
76            function restoreSelection($jq) {
77                var cookieVal = $.cookie("selectedCells"),
78                    cells, cell, selectionObj, x, y;
79
80                if (cookieVal) {
81                    selectionObj = $jq.wijgrid("selection");
82
83                    selectionObj.beginUpdate();
84
85                    selectionObj.clear();
86
87                    $.each(cookieVal.split(" "), function (index, item) {
88                        if (item) {
89                            cell = item.split(":");
90                            x = parseInt(cell[0], 10);
91                            y = parseInt(cell[1], 10);
92
93                            selectionObj.addRange(x, y, x, y);
94                        }
95                    });
96
97                    selectionObj.endUpdate();
98                }
99
100                selectionRestored = true;
101            }
102        });
103    </script>
104</head>
105<body class="demo-single">
106    <div class="container">
107        <div class="header">
108            <h2>
109                Save Sorting and Selection State</h2>
110        </div>
111        <div class="main demo">
112            <!-- Begin demo markup -->
113            <table id="demo">
114                <thead>
115                    <tr>
116                        <th>ID</th><th>Company</th><th>Name</th>
117                    </tr>
118                </thead>
119                <tbody>
120                    <tr>
121                        <td>ANATR</td><td>Ana Trujillo Emparedados y helados</td><td>Ana Trujillo</td>
122                    </tr>
123                    <tr>
124                        <td>ANTON</td><td>Antonio Moreno Taqueria</td><td>Antonio Moreno</td>
125                    </tr>
126                    <tr>
127                        <td>AROUT</td><td>Around the Horn</td><td>Thomas Hardy</td>
128                    </tr>
129                    <tr>
130                        <td>BERGS</td><td>Berglunds snabbkop</td><td>Christina Berglund</td>
131                    </tr>
132                </tbody>
133            </table>
134            <!-- End demo markup -->
135            <div class="demo-options">
136                <!-- Begin options markup -->
137                <!-- End options markup -->
138            </div>
139        </div>
140        <div class="footer demo-description">
141            <p>
142                Select any row or sort any column; the state will be stored in the cookie.
143            </p>
144        </div>
145    </div>
146</body>
147</html>
Note: See TracBrowser for help on using the repository browser.