@@ -41,12 +41,33 @@ var SchedulingCheck = React.createClass({
41
41
greyed : { } ,
42
42
sort : - 1 ,
43
43
reverse : false
44
- }
44
+ } ,
45
+ tableKey : 0 // so React knows to rerender the table
45
46
} ;
46
47
} ,
47
48
48
- updateTableState : function ( state ) {
49
- this . state . tableState = state ;
49
+ sortColumn : function ( column ) {
50
+ if ( this . state . tableState . sort === column ) {
51
+ this . setState ( {
52
+ tableState : React . addons . update ( this . state . tableState ,
53
+ { reverse : { $set : ! this . state . tableState . reverse } } ) ,
54
+ tableKey : this . state . tableKey + 1
55
+ } ) ;
56
+ } else {
57
+ this . setState ( {
58
+ tableState : React . addons . update ( this . state . tableState , { sort : { $set : column } , reverse : { $set : false } } ) ,
59
+ tableKey : this . state . tableKey + 1
60
+ } ) ;
61
+ }
62
+ } ,
63
+
64
+ greyRow : function ( item ) {
65
+ newkey = { } ;
66
+ newkey [ item ] = ! this . state . tableState . greyed [ item ] ;
67
+ this . setState ( {
68
+ tableState : React . addons . update ( this . state . tableState , { greyed : { $merge : newkey } } ) ,
69
+ tableKey : this . state . tableKey + 1
70
+ } ) ;
50
71
} ,
51
72
52
73
resetTable : function ( ) {
@@ -56,7 +77,7 @@ var SchedulingCheck = React.createClass({
56
77
sort : - 1 ,
57
78
reverse : false
58
79
} ,
59
- open : false
80
+ tableKey : this . state . tableKey + 1
60
81
} ) ;
61
82
62
83
} ,
@@ -113,7 +134,10 @@ var SchedulingCheck = React.createClass({
113
134
var data = JSON . parse ( this . state . data ) ; // Might not work on old browsers
114
135
var table ;
115
136
if ( data . headings . length == 0 ) {
116
- table = < SelectTable rows = { data . body } header = { false } saveState = { this . state . tableState } updateTableState = { this . updateTableState } /> ;
137
+ table = < SelectTable rows = { data . body } header = { false }
138
+ saveState = { this . state . tableState }
139
+ clickHeader = { this . sortColumn } clickRow = { this . greyRow }
140
+ key = { this . state . tableKey } /> ;
117
141
} else {
118
142
var columns = [ ] ;
119
143
for ( i = 0 ; i < data . headings . length ; i ++ ) {
@@ -123,7 +147,10 @@ var SchedulingCheck = React.createClass({
123
147
columns [ i ] = { key : String ( i ) , label : "--" } ;
124
148
}
125
149
}
126
- table = < SelectTable rows = { data . body } columns = { columns } header = { true } saveState = { this . state . tableState } updateTableState = { this . updateTableState } /> ;
150
+ table = < SelectTable rows = { data . body } columns = { columns }
151
+ header = { true } saveState = { this . state . tableState }
152
+ clickHeader = { this . sortColumn } clickRow = { this . greyRow }
153
+ key = { this . state . tableKey } /> ;
127
154
}
128
155
body = < div >
129
156
< div className = "placeholder" >
@@ -188,20 +215,18 @@ var SelectTable = React.createClass({
188
215
} ) . isRequired ,
189
216
header : React . PropTypes . bool . isRequired ,
190
217
columns : React . PropTypes . array ,
191
- updateTableState : React . PropTypes . func . isRequired
218
+ clickHeader : React . PropTypes . func . isRequired ,
219
+ clickRow : React . PropTypes . func . isRequired
192
220
} ,
193
221
194
222
getInitialState : function ( ) {
195
- // We will store the sorted column and whether each row is greyed out
196
223
return { sort : this . props . saveState . sort , greyed : this . props . saveState . greyed , reverse : this . props . saveState . reverse } ;
197
224
} ,
198
225
render : function ( ) {
199
- this . props . updateTableState ( this . state ) ;
200
- var me = this ;
201
226
// clone the rows
202
227
items = this . props . rows . slice ( ) ;
203
228
204
- items = _ . sortBy ( items , me . state . sort ) ;
229
+ items = _ . sortBy ( items , this . state . sort ) ;
205
230
206
231
if ( this . state . reverse ) items . reverse ( ) ;
207
232
@@ -241,17 +266,10 @@ var SelectTable = React.createClass({
241
266
} ,
242
267
243
268
onClickHeader : function ( e , column ) {
244
- if ( this . state . sort === column ) {
245
- this . setState ( { reverse : ! this . state . reverse } ) ;
246
- } else {
247
- this . setState ( { sort : column , reverse : false } ) ;
248
- }
269
+ this . props . clickHeader ( column ) ;
249
270
} ,
250
271
251
272
onClickRow : function ( e , item ) {
252
- // kind of kludgy but I can't figure out how to do this more nicely
253
- newgreyed = jQuery . extend ( { } , this . state . greyed ) ;
254
- newgreyed [ item ] = ! newgreyed [ item ] ;
255
- this . setState ( { greyed : newgreyed } ) ;
273
+ this . props . clickRow ( item ) ;
256
274
}
257
275
} ) ;
0 commit comments