@@ -16,6 +16,7 @@ const BBOX_Y_ADJUST = 10;
16
16
const use_minicharts = false ;
17
17
let sortOrder = false ;
18
18
let columnKey = '' ;
19
+ let pivotKey = '' ;
19
20
20
21
const removeStyles = async function ( ) {
21
22
const links = document . getElementsByTagName ( 'link' ) ;
@@ -245,9 +246,12 @@ const buildReportTable = function (
245
246
return ( dropTarget = null ) ;
246
247
} )
247
248
. on ( 'click' , function ( cell ) {
248
- const key = cell . column . id ;
249
+ console . log ( 'cell' ) ;
250
+ console . log ( cell ) ;
251
+ const column_key = cell . column . modelField . name ;
252
+ const pivot = cell . column . pivot_key ;
249
253
if ( cell . type !== 'pivot0' ) {
250
- updateSorting ( sortOrder , key ) ;
254
+ updateSorting ( sortOrder , column_key , pivot ) ;
251
255
sortOrder = ! sortOrder ;
252
256
}
253
257
} ) ;
@@ -645,21 +649,32 @@ looker.plugins.visualizations.add({
645
649
// Here goes the sorting then the vis is built again
646
650
// If order = true => ascending
647
651
// If order = false => descending
648
- const updateSorting = ( order , key ) => {
652
+ const updateSorting = ( order , key , pivot ) => {
649
653
columnKey = key ;
654
+ pivotKey = pivot ;
650
655
this . trigger ( 'updateConfig' , [
651
656
{ sorting : order ? 'ascending' : 'descending' } ,
652
657
] ) ;
653
658
} ;
654
659
655
660
if ( columnKey !== '' ) {
661
+ console . log ( `columnKey: ${ columnKey } ` ) ;
662
+ console . log ( `pivotKey: ${ pivotKey } ` ) ;
656
663
if ( config . sorting === 'ascending' ) {
657
664
data . sort ( ( a , b ) => {
658
- return d3 . ascending ( a [ columnKey ] . value , b [ columnKey ] . value ) ;
665
+ const value_1 =
666
+ pivotKey === '' ? a [ columnKey ] . value : a [ columnKey ] [ pivotKey ] . value ;
667
+ const value_2 =
668
+ pivotKey === '' ? b [ columnKey ] . value : b [ columnKey ] [ pivotKey ] . value ;
669
+ return d3 . ascending ( value_1 , value_2 ) ;
659
670
} ) ;
660
671
} else if ( config . sorting === 'descending' ) {
661
672
data . sort ( ( a , b ) => {
662
- return d3 . descending ( a [ columnKey ] . value , b [ columnKey ] . value ) ;
673
+ const value_1 =
674
+ pivotKey === '' ? a [ columnKey ] . value : a [ columnKey ] [ pivotKey ] . value ;
675
+ const value_2 =
676
+ pivotKey === '' ? b [ columnKey ] . value : b [ columnKey ] [ pivotKey ] . value ;
677
+ return d3 . descending ( value_1 , value_2 ) ;
663
678
} ) ;
664
679
}
665
680
}
0 commit comments