@@ -9,6 +9,7 @@ var PivotView = function (controller, container) {
99 "instance \"container\" into pivot table configuration." ) ;
1010
1111 this . tablesStack = [ ] ;
12+ this . selectedRows = { } ; // rowNumber: 1
1213
1314 numeral . call ( this ) ;
1415
@@ -150,6 +151,7 @@ PivotView.prototype.pushTable = function (opts) {
150151 if ( this . tablesStack . length ) {
151152 this . tablesStack [ this . tablesStack . length - 1 ] . FIXED_COLUMN_SIZES = this . FIXED_COLUMN_SIZES ;
152153 this . tablesStack [ this . tablesStack . length - 1 ] . savedSearch = this . savedSearch ;
154+ this . tablesStack [ this . tablesStack . length - 1 ] . selectedRows = this . selectedRows ;
153155 this . savedSearch = { restore : false , value : "" , columnIndex : 0 } ;
154156 tableElement . style . left = "100%" ;
155157 }
@@ -166,6 +168,7 @@ PivotView.prototype.pushTable = function (opts) {
166168 } ) ;
167169
168170 this . FIXED_COLUMN_SIZES = [ ] ;
171+ this . selectedRows = { } ;
169172 this . elements . base . appendChild ( tableElement ) ;
170173 this . elements . tableContainer = tableElement ;
171174 this . pagination = pg ;
@@ -189,6 +192,7 @@ PivotView.prototype.popTable = function () {
189192 this . pagination = ( currentTable = this . tablesStack [ this . tablesStack . length - 1 ] ) . pagination ;
190193 if ( currentTable . FIXED_COLUMN_SIZES ) this . FIXED_COLUMN_SIZES = currentTable . FIXED_COLUMN_SIZES ;
191194 if ( currentTable . savedSearch ) this . savedSearch = currentTable . savedSearch ;
195+ if ( currentTable . selectedRows ) this . selectedRows = currentTable . selectedRows ;
192196
193197 setTimeout ( function ( ) {
194198 garbage . element . parentNode . removeChild ( garbage . element ) ;
@@ -237,9 +241,7 @@ PivotView.prototype.dataChanged = function (data) {
237241
238242 if ( this . controller . CONFIG . pagination ) this . pagination . on = true ;
239243 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 = { } ;
243245 this . pagination . page = 0 ;
244246 this . pagination . pages = Math . ceil ( dataRows / this . pagination . rows ) ;
245247 if ( this . pagination . pages < 2 ) this . pagination . on = false ;
@@ -505,6 +507,23 @@ PivotView.prototype.colorNameToRGB = function (name) {
505507 }
506508} ;
507509
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+
508527/**
509528 * Size updater for LPT.
510529 * Do not affect scroll positions in this function.
@@ -728,6 +747,7 @@ PivotView.prototype.renderRawData = function (data) {
728747 COLUMN_RESIZE_ON = ! ! this . controller . CONFIG . columnResizing ,
729748 LISTING = info . leftHeaderColumnsNumber === 0 ,
730749 SEARCH_ENABLED = LISTING && this . controller . CONFIG [ "enableSearch" ] ,
750+ LISTING_SELECT_ENABLED = this . controller . CONFIG [ "enableListingSelect" ] ,
731751 RESIZE_ANIMATION = ! ! this . controller . CONFIG [ "columnResizeAnimation" ] ,
732752
733753 container = this . elements . tableContainer ,
@@ -856,7 +876,26 @@ PivotView.prototype.renderRawData = function (data) {
856876 var renderHeader = function ( xFrom , xTo , yFrom , yTo , targetElement ) {
857877
858878 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+ }
860899
861900 for ( y = yFrom ; y < yTo ; y ++ ) {
862901 for ( x = xFrom ; x < xTo ; x ++ ) {
0 commit comments