@@ -40,6 +40,8 @@ import {
4040 VuuUIMessageInRPCEditSuccess ,
4141} from "../vuuUIMessageTypes" ;
4242
43+ import { groupRows } from "./group-utils" ;
44+
4345export interface ArrayDataSourceConstructorProps
4446 extends Omit < DataSourceConstructorProps , "bufferSize" | "table" > {
4547 columnDescriptors : ColumnDescriptor [ ] ;
@@ -96,6 +98,7 @@ export class ArrayDataSource
9698 private status = "initialising" ;
9799 private disabled = false ;
98100 private filteredData : undefined | DataSourceRow [ ] ;
101+ private groupedData : undefined | DataSourceRow [ ] ;
99102 private suspended = false ;
100103 private clientCallback : SubscribeCallback | undefined ;
101104 private tableMeta : VuuTableMeta ;
@@ -312,7 +315,7 @@ export class ArrayDataSource
312315 this . rangeChangeRowset === "delta" && ! forceFullRefresh
313316 ? rangeNewItems ( this . lastRangeServed , this . #range)
314317 : this . #range;
315- const data = this . filteredData ?? this . #data;
318+ const data = this . groupedData ?? this . filteredData ?? this . #data;
316319 this . clientCallback ?.( {
317320 clientViewportId : this . viewport ,
318321 rows : data
@@ -364,11 +367,6 @@ export class ArrayDataSource
364367 debug ?.( `filter ${ JSON . stringify ( filter ) } ` ) ;
365368 // TODO should we wait until server ACK before we assign #sort ?
366369
367- this . #config = {
368- ...this . #config,
369- filter,
370- } ;
371-
372370 this . #config = {
373371 ...this . #config,
374372 filter,
@@ -395,7 +393,28 @@ export class ArrayDataSource
395393 }
396394
397395 set groupBy ( groupBy : VuuGroupBy ) {
398- // this.#config.groupBy = groupBy;
396+ this . #config = {
397+ ...this . #config,
398+ groupBy,
399+ } ;
400+
401+ if ( groupBy . length ) {
402+ console . time ( "group" ) ;
403+ this . groupedData = groupRows ( this . #data, groupBy , this . #columnMap) . map (
404+ ( row , i ) => {
405+ const dolly = row . slice ( ) as DataSourceRow ;
406+ dolly [ 0 ] = i ;
407+ dolly [ 1 ] = i ;
408+ return dolly ;
409+ }
410+ ) ;
411+ console . timeEnd ( "group" ) ;
412+ } else {
413+ this . groupedData = undefined ;
414+ }
415+ this . setRange ( resetRange ( this . #range) , true ) ;
416+
417+ this . emit ( "config" , this . #config) ;
399418 }
400419
401420 get title ( ) {
0 commit comments