@@ -20,7 +20,7 @@ function enable_dragging() {
2020
2121function selected_deselected ( el ) {
2222 // This is a pointer to the selection array
23- const selection = globalSpyCTableIndex . get ( el . tableId ) ;
23+ const selection = globalSpyCTableIndex . get ( el . dataset . table_id ) ;
2424 let is_selected = el . classList . contains ( 'selected' ) ;
2525 if ( is_selected ) {
2626 selection . delete ( el ) ;
@@ -33,19 +33,19 @@ function selected_deselected(el) {
3333 }
3434 spyCTableSelectionBuffer . length = 0 ;
3535 for ( const element of selection ) {
36- spyCTableSelectionBuffer . push ( element . coords ) ;
36+ spyCTableSelectionBuffer . push ( element . dataset . coords ) ;
3737 }
38- Shiny . setInputValue ( el . inputId , spyCTableSelectionBuffer ) ;
38+ Shiny . setInputValue ( el . dataset . table_id + '_cells_selected' , spyCTableSelectionBuffer ) ;
3939}
4040
41- function mouse_over_event ( ) {
41+ function mouse_over_event ( el ) {
4242 if ( is_dragging ) {
43- selected_deselected ( this )
43+ selected_deselected ( el )
4444 }
4545}
4646
47- function mouse_down_event ( ) {
48- selected_deselected ( this )
47+ function mouse_down_event ( el ) {
48+ selected_deselected ( el )
4949}
5050
5151// This function is to deselect everything in the table
@@ -58,7 +58,7 @@ function spyctable_deselect_all(tableId) {
5858 }
5959 selection . clear ( ) ;
6060 spyCTableSelectionBuffer . length = 0 ;
61- Shiny . setInputValue ( el . inputId , spyCTableSelectionBuffer ) ;
61+ Shiny . setInputValue ( tableId + '_cells_selected' , spyCTableSelectionBuffer ) ;
6262 }
6363}
6464
@@ -68,43 +68,6 @@ addEventListener("mouseup", (_event) => {
6868 disable_dragging ( ) ;
6969} ) ;
7070
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-
10871function fromHTML ( html , trim = true ) {
10972 // Process the HTML string.
11073 html = trim ? html . trim ( ) : html ;
@@ -137,16 +100,8 @@ spyCTableBinding.renderValue = function(el, msg) {
137100 selection = new Set ( ) ;
138101 globalSpyCTableIndex . set ( id , selection ) ;
139102 }
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 ) ;
150105 el . appendChild ( table ) ;
151106
152107 let scroll_y = el . getAttribute ( "scroll-y" ) ;
0 commit comments