File tree Expand file tree Collapse file tree 4 files changed +27
-30
lines changed Expand file tree Collapse file tree 4 files changed +27
-30
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ $.widget( "ui.datasource", {
15
15
return this . data ;
16
16
} ,
17
17
18
+ // TODO this needs to be applied to init options as well, to work sort: "prop" work
18
19
_setOption : function ( key , value ) {
19
20
// reset offset to 0 when changing limit
20
21
// TODO actually only necessary when offset > offset + new limit
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ $.widget( "ui.grid", {
21
21
this . _columns ( ) ;
22
22
this . _rowTemplate ( ) ;
23
23
this . element . addClass ( "ui-widget" ) ;
24
- this . element . find ( "th" ) . addClass ( "ui-widget-header " ) ;
24
+ this . element . find ( "th" ) . addClass ( "ui-state-default " ) ;
25
25
this . element . delegate ( "tbody > tr" , "click" , function ( event ) {
26
26
that . _trigger ( "select" , event , {
27
27
item : $ ( this ) . data ( "grid-item" )
Original file line number Diff line number Diff line change 68
68
} ) ;
69
69
</ script >
70
70
< style >
71
- .ui-menu {
72
- position : absolute;
71
+ thead th {
72
+ cursor : default;
73
+ }
74
+ thead th .ui-icon {
75
+ display : none;
76
+ height : 12px ;
77
+ }
78
+ thead th .sorted .ui-icon-asc {
79
+ display : inline-block;
80
+ }
81
+ thead th .sorted-desc .ui-icon-desc {
82
+ display : inline-block;
73
83
}
74
84
tfoot td {
75
85
text-align : center;
81
91
</ head >
82
92
< body >
83
93
84
- < script type ="text/x-jquery-tmpl " id ="menu-tmpl ">
85
- < ul >
86
- < li >
87
- < a href = "#" data-sort = "asc" > Sort Ascending</ a >
88
- </ li >
89
- < li >
90
- < a href = "#" data-sort = "desc" > Sort Descending</ a >
91
- </ li >
92
- </ ul >
93
- </ script >
94
-
95
94
< h2 > Movies! Click header for sort menu, use inputs for filtering, pager for paging</ h2 >
96
95
< table id ="movies ">
97
96
< thead >
Original file line number Diff line number Diff line change 1
1
$ . widget ( "spf.menugrid" , {
2
2
_create : function ( ) {
3
- var source = this . element . data ( "grid" ) . options . source ;
4
- this . element . find ( "th" ) . each ( function ( ) {
5
- var header = $ ( this ) ,
6
- field = header . data ( "field" ) ;
7
- var menu = $ ( "#menu-tmpl" ) . tmpl ( ) . appendTo ( this ) . menu ( {
8
- select : function ( event , ui ) {
9
- source
10
- . option ( "sort" ,
11
- ui . item . find ( "a" ) . data ( "sort" ) === "asc" ? field : "-" + field )
12
- . refresh ( ) ;
13
- menu . hide ( ) ;
14
- }
15
- } ) . popup ( {
16
- trigger : header
17
- } ) ;
18
- } ) ;
3
+ var grid = this . element . data ( "grid" ) ;
4
+ var source = grid . options . source ;
5
+ var headers = this . element . find ( "th" ) ;
6
+ this . _hoverable ( headers ) ;
7
+ headers . click ( function ( ) {
8
+ headers . not ( this ) . removeClass ( "sorted sorted-desc" ) ;
9
+ var column = grid . options . columns [ this . cellIndex ] ;
10
+ var sorted = $ ( this ) . hasClass ( "sorted" ) ;
11
+ $ ( this ) . toggleClass ( "sorted" , ! sorted ) . toggleClass ( "sorted-desc" , sorted ) ;
12
+ source
13
+ . option ( "sort" , ( sorted ? "-" : "" ) + column . property )
14
+ . refresh ( ) ;
15
+ } ) . append ( '<span class="ui-icon-asc ui-icon ui-icon-carat-1-n"></span><span class="ui-icon-desc ui-icon ui-icon-carat-1-s"></span>' ) ;
19
16
20
17
var thead = this . element . find ( "thead" ) ;
21
18
var inputs = thead . children ( )
You can’t perform that action at this time.
0 commit comments