@@ -44,11 +44,13 @@ const GRAND_TOTAL_VALUE = 'Grand Total';
4444
4545// TODO:
4646// - totals row formatting [DONE]
47- // - totals row: copy cell unformatted
48- // - copy selection with headers - fix column mapping, fix case with only totals row selected
47+ // - totals row: copy cell unformatted [DONE]
48+ // - copy selection with headers - fix column mapping, fix case with only totals row selected [DONE]
49+ // - ^ unit tests
4950// - totals column move to back
50- // - col based operations
51+ // - col based operations - save/restore settings on model change
5152// - flags to hide unsupported table options - go to row, filters, search, organize columns, etc
53+ // - fix sub/unsubscribe on model change
5254
5355/**
5456 * Model which proxies calls to IrisGridModel.
@@ -285,66 +287,19 @@ class IrisGridSimplePivotModel extends IrisGridModel {
285287 return this . model . rowCount + ( this . schema . hasTotals ? 1 : 0 ) ;
286288 }
287289
288- valueForCell ( x : ModelIndex , y : ModelIndex ) : unknown {
289- if ( this . schema . hasTotals && y === this . rowCount - 1 ) {
290- return this . totalsRowMap . get ( this . columns [ x ] . name ) ;
291- }
292-
293- return this . model . valueForCell ( x , y ) ;
294- }
295-
296290 sourceColumn ( x : ModelIndex , _ : ModelIndex ) : DhType . Column {
297291 // TODO:
298292 return this . columns [ x ] ; // - this.schema.rowColNames.length];
299293 }
300294
301- textValueForCell ( x : ModelIndex , y : ModelIndex ) : string | null | undefined {
302- // Use a separate cache from memoization just for the strings that are currently displayed
303- const value = this . valueForCell ( x , y ) ;
304- if ( value === null ) {
305- return null ;
306- }
307- if ( value === undefined ) {
308- return undefined ;
309- }
310-
311- if ( ! isIrisGridTableModelTemplate ( this . model ) ) {
312- throw new Error ( 'Invalid model, textValueForCell not available' ) ;
313- }
314-
315- const column = this . sourceColumn ( x , y ) ;
316-
317- // TODO:
318- const hasCustomColumnFormat = this . model . getCachedCustomColumnFormatFlag (
319- this . formatter ,
320- column . name ,
321- column . type
322- ) ;
323- let formatOverride ;
324- if ( ! hasCustomColumnFormat ) {
325- const formatForCell = this . formatForCell ( x , y ) ;
326- if ( formatForCell ?. formatString != null ) {
327- formatOverride = formatForCell ;
328- }
329- }
330- const text = this . model . displayString (
331- value ,
332- column . type ,
333- column . name ,
334- formatOverride
335- ) ;
336- this . model . cacheFormattedValue ( x , y , text ) ;
337- return text ;
338- }
339-
340- textForCell ( x : ModelIndex , y : ModelIndex ) : string {
295+ valueForCell ( x : ModelIndex , y : ModelIndex ) : unknown {
341296 if ( this . schema . hasTotals && y === this . rowCount - 1 ) {
342297 if ( x >= this . schema . rowColNames . length ) {
343- return this . textValueForCell ( x , y ) ?? '' ;
298+ return this . totalsRowMap . get ( this . columns [ x ] . name ) ;
344299 }
345- return x === 0 ? GRAND_TOTAL_VALUE : '' ;
300+ return x === 0 ? GRAND_TOTAL_VALUE : undefined ;
346301 }
347- return this . model . textForCell ( x , y ) ;
302+ return this . model . valueForCell ( x , y ) ;
348303 }
349304
350305 setTotalsTable ( totalsTable : DhType . Table | null ) : void {
@@ -695,13 +650,20 @@ class IrisGridSimplePivotModel extends IrisGridModel {
695650 ? [ ]
696651 : await this . model . snapshot (
697652 tableRanges ,
698- includeHeaders ,
653+ false ,
699654 formatValue ,
700655 consolidateRanges
701656 ) ;
702657
703658 const columns = IrisGridUtils . columnsFromRanges ( consolidated , this . columns ) ;
704659
660+ if ( includeHeaders ) {
661+ const headerRow = columns . map (
662+ column => this . columnMap . get ( column . name ) ?? column . name
663+ ) ;
664+ result . unshift ( headerRow ) ;
665+ }
666+
705667 if ( hasTotals ) {
706668 const rowData = columns . map ( column => {
707669 const index = this . getColumnIndexByName ( column . name ) ;
0 commit comments