@@ -13,9 +13,11 @@ function onRender(event: Event): void {
1313 var other_args = ( event as CustomEvent < RenderData > ) . detail . args . other_args
1414 var dt_args = ( event as CustomEvent < RenderData > ) . detail . args . dt_args
1515
16- if ( other_args . downsampling_warning ) {
17- dt_args [ "fnInfoCallback" ] = function ( oSettings :any , iStart :number , iEnd :number , iMax :number , iTotal :number , sPre :string ) { return sPre + ' (' +
18- other_args . downsampling_warning + ')' }
16+ if ( other_args . downsampling_warning ) {
17+ dt_args [ "fnInfoCallback" ] = function ( oSettings : any , iStart : number , iEnd : number , iMax : number , iTotal : number , sPre : string ) {
18+ return sPre + ' (' +
19+ other_args . downsampling_warning + ')'
20+ }
1921 }
2022
2123 // As we can't pass the dt_args other than in the
@@ -29,34 +31,42 @@ function onRender(event: Event): void {
2931 table . setAttribute ( 'style' , other_args . style )
3032
3133 dt = new DataTable ( table , dt_args )
32- if ( other_args . caption ) {
34+ if ( other_args . caption ) {
3335 dt . caption ( other_args . caption )
3436 }
3537
36- function export_selected_rows ( ) {
37- let selected_rows :Array < number > = Array . from ( dt . rows ( { selected : true } ) . indexes ( ) ) ;
38+ let full_row_count : number = other_args . full_row_count ;
39+ let data_row_count : number = dt_args . data . length ;
40+
41+ let bottom_half = data_row_count / 2 ;
42+ let top_half = full_row_count - bottom_half ;
3843
39- let full_row_count :number = other_args . full_row_count ;
40- let data_row_count :number = dt_args . data . length ;
44+ // The model selected rows are for the full table, so
45+ // we map them to the actual data
46+ let org_selected_rows = Array . from (
47+ other_args . selected_rows
48+ . filter ( ( i : number ) => i >= 0 && i < full_row_count && ( i < bottom_half || i >= top_half ) )
49+ . map ( ( i : number ) => ( i < bottom_half ) ? i : i - full_row_count + data_row_count ) ) ;
50+ dt . rows ( org_selected_rows ) . select ( ) ;
51+
52+ function export_selected_rows ( ) {
53+ let selected_rows : Array < number > = Array . from ( dt . rows ( { selected : true } ) . indexes ( ) ) ;
4154
4255 // Here the selected rows are for the datatable.
43- // We convert them back to the full table
44- if ( data_row_count < full_row_count ) {
45- let bottom_half = data_row_count / 2 ;
46- selected_rows = selected_rows . map (
47- ( x :number , i :number ) => ( x < bottom_half ? x : x + full_row_count - data_row_count ) ) ;
48- }
49-
50- Streamlit . setComponentValue ( { selected_rows} ) ;
51- } ;
52-
53- dt . on ( 'select' , function ( e : any , dt : any , type : any , indexes : any ) {
54- export_selected_rows ( ) ;
55- } ) ;
56-
57- dt . on ( 'deselect' , function ( e : any , dt : any , type : any , indexes : any ) {
58- export_selected_rows ( ) ;
59- } ) ;
56+ // We convert them back to the full table
57+ selected_rows = Array . from ( selected_rows . map (
58+ ( i : number ) => ( i < bottom_half ? i : i + full_row_count - data_row_count ) ) ) ;
59+
60+ Streamlit . setComponentValue ( { selected_rows } ) ;
61+ } ;
62+
63+ dt . on ( 'select' , function ( e : any , dt : any , type : any , indexes : any ) {
64+ export_selected_rows ( ) ;
65+ } ) ;
66+
67+ dt . on ( 'deselect' , function ( e : any , dt : any , type : any , indexes : any ) {
68+ export_selected_rows ( ) ;
69+ } ) ;
6070
6171 // we recalculate the height
6272 Streamlit . setFrameHeight ( )
0 commit comments