@@ -9,6 +9,7 @@ var PivotView = function (controller, container) {
9
9
"instance \"container\" into pivot table configuration." ) ;
10
10
11
11
this . tablesStack = [ ] ;
12
+ this . selectedRows = { } ; // rowNumber: 1
12
13
13
14
numeral . call ( this ) ;
14
15
@@ -150,6 +151,7 @@ PivotView.prototype.pushTable = function (opts) {
150
151
if ( this . tablesStack . length ) {
151
152
this . tablesStack [ this . tablesStack . length - 1 ] . FIXED_COLUMN_SIZES = this . FIXED_COLUMN_SIZES ;
152
153
this . tablesStack [ this . tablesStack . length - 1 ] . savedSearch = this . savedSearch ;
154
+ this . tablesStack [ this . tablesStack . length - 1 ] . selectedRows = this . selectedRows ;
153
155
this . savedSearch = { restore : false , value : "" , columnIndex : 0 } ;
154
156
tableElement . style . left = "100%" ;
155
157
}
@@ -166,6 +168,7 @@ PivotView.prototype.pushTable = function (opts) {
166
168
} ) ;
167
169
168
170
this . FIXED_COLUMN_SIZES = [ ] ;
171
+ this . selectedRows = { } ;
169
172
this . elements . base . appendChild ( tableElement ) ;
170
173
this . elements . tableContainer = tableElement ;
171
174
this . pagination = pg ;
@@ -189,6 +192,7 @@ PivotView.prototype.popTable = function () {
189
192
this . pagination = ( currentTable = this . tablesStack [ this . tablesStack . length - 1 ] ) . pagination ;
190
193
if ( currentTable . FIXED_COLUMN_SIZES ) this . FIXED_COLUMN_SIZES = currentTable . FIXED_COLUMN_SIZES ;
191
194
if ( currentTable . savedSearch ) this . savedSearch = currentTable . savedSearch ;
195
+ if ( currentTable . selectedRows ) this . selectedRows = currentTable . selectedRows ;
192
196
193
197
setTimeout ( function ( ) {
194
198
garbage . element . parentNode . removeChild ( garbage . element ) ;
@@ -237,9 +241,7 @@ PivotView.prototype.dataChanged = function (data) {
237
241
238
242
if ( this . controller . CONFIG . pagination ) this . pagination . on = true ;
239
243
this . pagination . rows = this . controller . CONFIG . pagination || Infinity ;
240
- //? this.controller.CONFIG.pagination
241
- //+ data.info.topHeaderRowsNumber + (data.info.SUMMARY_SHOWN ? 1 : 0)
242
- //: Infinity;
244
+ this . selectedRows = { } ;
243
245
this . pagination . page = 0 ;
244
246
this . pagination . pages = Math . ceil ( dataRows / this . pagination . rows ) ;
245
247
if ( this . pagination . pages < 2 ) this . pagination . on = false ;
@@ -505,6 +507,23 @@ PivotView.prototype.colorNameToRGB = function (name) {
505
507
}
506
508
} ;
507
509
510
+ /**
511
+ * @param {boolean } select - select or not.
512
+ * @param {number } rowNumber - row number start from 0.
513
+ */
514
+ PivotView . prototype . selectRow = function ( select , rowNumber ) {
515
+
516
+ if ( select )
517
+ this . selectedRows [ rowNumber ] = 1 ;
518
+ else
519
+ delete this . selectedRows [ rowNumber ] ;
520
+
521
+ if ( typeof this . controller . CONFIG . triggers [ "rowSelect" ] === "function" ) {
522
+ this . controller . CONFIG . triggers [ "rowSelect" ] ( this . controller . getSelectedRows ( ) ) ;
523
+ }
524
+
525
+ } ;
526
+
508
527
/**
509
528
* Size updater for LPT.
510
529
* Do not affect scroll positions in this function.
@@ -728,6 +747,7 @@ PivotView.prototype.renderRawData = function (data) {
728
747
COLUMN_RESIZE_ON = ! ! this . controller . CONFIG . columnResizing ,
729
748
LISTING = info . leftHeaderColumnsNumber === 0 ,
730
749
SEARCH_ENABLED = LISTING && this . controller . CONFIG [ "enableSearch" ] ,
750
+ LISTING_SELECT_ENABLED = this . controller . CONFIG [ "enableListingSelect" ] ,
731
751
RESIZE_ANIMATION = ! ! this . controller . CONFIG [ "columnResizeAnimation" ] ,
732
752
733
753
container = this . elements . tableContainer ,
@@ -856,7 +876,26 @@ PivotView.prototype.renderRawData = function (data) {
856
876
var renderHeader = function ( xFrom , xTo , yFrom , yTo , targetElement ) {
857
877
858
878
var vertical = targetElement === LHTHead ,
859
- rendered , separatelyGrouped , tr , th , div ;
879
+ rendered , separatelyGrouped , tr , th , div , checkbox ;
880
+
881
+ if ( xFrom === xTo && LISTING_SELECT_ENABLED ) { // listing
882
+ for ( y = yFrom ; y < yTo ; y ++ ) {
883
+ tr = document . createElement ( "tr" ) ;
884
+ th = document . createElement ( "td" ) ;
885
+ checkbox = document . createElement ( "input" ) ;
886
+ checkbox . setAttribute ( "type" , "checkbox" ) ;
887
+ checkbox . checked = ! ! _ . selectedRows [ y ] ;
888
+ th . setAttribute ( "style" , "padding: 0 !important;" ) ;
889
+ checkbox . addEventListener ( "change" , ( function ( y ) { return function ( e ) {
890
+ _ . selectRow . call ( _ , ( e . srcElement || e . target ) . checked , y ) ;
891
+ } } ) ( y ) ) ;
892
+ th . appendChild ( checkbox ) ;
893
+ tr . appendChild ( th ) ;
894
+ primaryRows . push ( th ) ;
895
+ targetElement . appendChild ( tr ) ;
896
+ }
897
+ return ;
898
+ }
860
899
861
900
for ( y = yFrom ; y < yTo ; y ++ ) {
862
901
for ( x = xFrom ; x < xTo ; x ++ ) {
0 commit comments