@@ -20,7 +20,7 @@ function enable_dragging() {
20
20
21
21
function selected_deselected ( el ) {
22
22
// This is a pointer to the selection array
23
- const selection = globalSpyCTableIndex . get ( el . tableId ) ;
23
+ const selection = globalSpyCTableIndex . get ( el . dataset . table_id ) ;
24
24
let is_selected = el . classList . contains ( 'selected' ) ;
25
25
if ( is_selected ) {
26
26
selection . delete ( el ) ;
@@ -33,19 +33,19 @@ function selected_deselected(el) {
33
33
}
34
34
spyCTableSelectionBuffer . length = 0 ;
35
35
for ( const element of selection ) {
36
- spyCTableSelectionBuffer . push ( element . coords ) ;
36
+ spyCTableSelectionBuffer . push ( element . dataset . coords ) ;
37
37
}
38
- Shiny . setInputValue ( el . inputId , spyCTableSelectionBuffer ) ;
38
+ Shiny . setInputValue ( el . dataset . table_id + '_cells_selected' , spyCTableSelectionBuffer ) ;
39
39
}
40
40
41
- function mouse_over_event ( ) {
41
+ function mouse_over_event ( el ) {
42
42
if ( is_dragging ) {
43
- selected_deselected ( this )
43
+ selected_deselected ( el )
44
44
}
45
45
}
46
46
47
- function mouse_down_event ( ) {
48
- selected_deselected ( this )
47
+ function mouse_down_event ( el ) {
48
+ selected_deselected ( el )
49
49
}
50
50
51
51
// This function is to deselect everything in the table
@@ -58,7 +58,7 @@ function spyctable_deselect_all(tableId) {
58
58
}
59
59
selection . clear ( ) ;
60
60
spyCTableSelectionBuffer . length = 0 ;
61
- Shiny . setInputValue ( el . inputId , spyCTableSelectionBuffer ) ;
61
+ Shiny . setInputValue ( tableId + '_cells_selected' , spyCTableSelectionBuffer ) ;
62
62
}
63
63
}
64
64
@@ -68,43 +68,6 @@ addEventListener("mouseup", (_event) => {
68
68
disable_dragging ( ) ;
69
69
} ) ;
70
70
71
- function build_tbody ( tableId , inputId , len_x , len_y , data , keys ) {
72
- var tbody = document . createElement ( "tbody" ) ;
73
-
74
- // If the user clicks then we enable dragging
75
- tbody . onmousedown = enable_dragging ;
76
-
77
- // If the user's mouse leaves the table we disable dragging
78
- tbody . onmouseleave = disable_dragging ;
79
-
80
- // Just in case, if the mouse just entered the table we
81
- // disable dragging aswell
82
- tbody . onmouseenter = disable_dragging ;
83
-
84
- const fragment = document . createDocumentFragment ( ) ;
85
-
86
- for ( var i = 0 ; i < len_y ; i ++ ) {
87
- var current_row = document . createElement ( "tr" ) ;
88
- for ( var c = 0 ; c < len_x ; c ++ ) {
89
- var current_cel = document . createElement ( "td" ) ;
90
- current_cel . coords = [ c , i ] ;
91
- current_cel . innerText = data [ keys [ c ] ] [ i ] ;
92
- current_cel . classList . add ( "user-select-none" ) ;
93
- //We passed the pointer to every single cell
94
- current_cel . tableId = tableId ;
95
- current_cel . onmouseover = mouse_over_event ;
96
- current_cel . onmousedown = mouse_down_event ;
97
- current_cel . inputId = inputId ;
98
- current_row . appendChild ( current_cel ) ;
99
- }
100
- fragment . appendChild ( current_row ) ;
101
- }
102
-
103
- tbody . appendChild ( fragment ) ;
104
-
105
- return tbody ;
106
- }
107
-
108
71
function fromHTML ( html , trim = true ) {
109
72
// Process the HTML string.
110
73
html = trim ? html . trim ( ) : html ;
@@ -137,16 +100,8 @@ spyCTableBinding.renderValue = function(el, msg) {
137
100
selection = new Set ( ) ;
138
101
globalSpyCTableIndex . set ( id , selection ) ;
139
102
}
140
- let data = msg . data ;
141
- let thead_content = msg . thead ;
142
- let keys = Object . keys ( data ) ;
143
- let len_x = keys . length ;
144
- let len_y = data [ keys [ 0 ] ] . length ;
145
- var table = document . createElement ( "table" ) ;
146
- table . classList . add ( "table" ) ;
147
- table . id = id + '_inner_table' ;
148
- table . appendChild ( fromHTML ( thead_content ) ) ;
149
- table . appendChild ( build_tbody ( id , inputId , len_x , len_y , data , keys ) ) ;
103
+
104
+ var table = fromHTML ( msg . html ) ;
150
105
el . appendChild ( table ) ;
151
106
152
107
let scroll_y = el . getAttribute ( "scroll-y" ) ;
0 commit comments