@@ -32,13 +32,20 @@ $.extend(gtShinyBinding, {
32
32
if ( reactableElement ) {
33
33
var rows = reactableElement . querySelectorAll ( '.rt-tr' ) ;
34
34
if ( rows . length > 0 ) {
35
- if ( ! reactableElement . __clickListenerAdded ) {
36
- reactableElement . addEventListener ( 'click' , function ( ) {
37
- el . __clickFlag = true ;
35
+ // Listener so we know it's an actual click, not another state change.
36
+ body_rows = reactableElement . querySelectorAll ( '.rt-tbody .rt-tr' ) ;
37
+ if ( body_rows . length > 0 ) {
38
+ body_rows . forEach ( function ( row ) {
39
+ if ( ! row . __clickListenerAdded ) {
40
+ row . addEventListener ( 'click' , function ( ) {
41
+ el . __clickFlag = true ;
42
+ } ) ;
43
+ row . __clickListenerAdded = true ;
44
+ }
38
45
} ) ;
39
- reactableElement . __clickListenerAdded = true ;
40
46
}
41
47
48
+ // State change listener, so we fire getValue *after* the state updates.
42
49
if ( ! reactableElement . __reactableStateChangeListener ) {
43
50
reactableElement . __reactableStateChangeListener = function ( ) {
44
51
$ ( el ) . trigger ( 'change.gtShiny' ) ;
@@ -90,24 +97,27 @@ $.extend(gtShinyBinding, {
90
97
this . initializeListener ( el ) ;
91
98
return ; // Table is reloading or not fully initialized
92
99
}
100
+
93
101
var reactableElement = this . getReactable ( el ) ;
94
- if ( reactableElement ) {
95
- var selectedRows = Reactable . getState ( reactableElement . id ) . selected ;
96
- if ( selectedRows === undefined ) {
97
- return null ;
98
- } else if ( selectedRows . length === 0 ) {
99
- if ( el . __clickFlag ) {
100
- el . __clickFlag = false ;
101
- return [ 0 ] ; // [0] if nothing is selected due to user click
102
- } else {
103
- return null ; // null if table is initializing or reloading
104
- }
105
- } else {
102
+ if ( ! reactableElement ) {
103
+ return ; // Initialization is finishing, state will report when finished.
104
+ }
105
+
106
+ var selectedRows = Reactable . getState ( reactableElement . id ) . selected ;
107
+ if ( selectedRows === undefined ) {
108
+ return ; // Initialization is finishing, state will report when finished.
109
+ }
110
+
111
+ if ( selectedRows . length === 0 ) {
112
+ if ( el . __clickFlag ) {
106
113
el . __clickFlag = false ;
107
- return selectedRows . map ( function ( row ) { return row + 1 ; } ) ;
114
+ return [ 0 ] ; // [0] if nothing is selected due to user click
108
115
}
116
+ return null ; // null if table is initializing or reloading
109
117
}
110
- return null ;
118
+
119
+ el . __clickFlag = false ;
120
+ return selectedRows . map ( function ( row ) { return row + 1 ; } ) ;
111
121
} ,
112
122
/**
113
123
* Sets the value of the selected rows in the gtShiny element.
0 commit comments