сряда, 15 януари 2014 г.

JavaScript Grid Sorting

The ShieldUI Grid component supports sorting out of the box. The default sorting is enabled by setting the sorting property to true.
This is demonstrated in the following code snippet:
1
2
3
4
5
6
7
8
9
$("#grid3").shieldGrid({
     dataSource: {
         data: [
            { ID: 1, name: "name1" },
            { ID: 2, name: "name2" }
        ]
     },
     sorting: true
});
Sorting programatically
One can also sort the ShieldUI grid component programatically, without relying on the standard user header click to initiate the sort.
This can be done programatically, for example by clickin on a button outside the grid and calling the sort function. This is demonstrated in the code snippet below:
1
2
3
4
function sortDesc() {
    $("#grid1").swidget().sort("UnitPrice", true, false);
}
As can be seen from the code, the approach requires:
1.Finding the grid container by id.
2.Calling the sort method, by passing it the column/field name as a first agrument.
The following example demonstrates the available sorting modes in the control.

Няма коментари:

Публикуване на коментар