diff --git a/packages/datalib/src/GridDisplay.ts b/packages/datalib/src/GridDisplay.ts index 4f184318..2fa08279 100644 --- a/packages/datalib/src/GridDisplay.ts +++ b/packages/datalib/src/GridDisplay.ts @@ -157,7 +157,7 @@ export abstract class GridDisplay { } get hiddenColumnIndexes() { - return (this.config.hiddenColumns || []).map(x => _.findIndex(this.columns, y => y.uniqueName == x)); + return (this.config.hiddenColumns || []).map(x => _.findIndex(this.allColumns, y => y.uniqueName == x)); } isColumnChecked(column: DisplayColumn) { diff --git a/packages/web/src/datagrid/DataGridCore.svelte b/packages/web/src/datagrid/DataGridCore.svelte index 6cbec73c..592607ba 100644 --- a/packages/web/src/datagrid/DataGridCore.svelte +++ b/packages/web/src/datagrid/DataGridCore.svelte @@ -697,6 +697,10 @@ // $: console.log('rowHeight', rowHeight); // $: console.log('containerHeight', containerHeight); + // $: console.log('COLUMNS', columns); + // $: console.log('realColumnUniqueNames', realColumnUniqueNames); + // $: console.log('columnSizes.realCount', columnSizes.realCount); + $: realColumnUniqueNames = _.range(columnSizes.realCount).map( realIndex => (columns[columnSizes.realToModel(realIndex)] || {}).uniqueName ); @@ -1317,7 +1321,10 @@ {:else if isDynamicStructure && isLoadedAll && grider?.rowCount == 0}
- + {#if display.filterCount > 0} display.clearFilters()} /> {/if} diff --git a/packages/web/src/datagrid/SeriesSizes.ts b/packages/web/src/datagrid/SeriesSizes.ts index f221a4c5..483d5c50 100644 --- a/packages/web/src/datagrid/SeriesSizes.ts +++ b/packages/web/src/datagrid/SeriesSizes.ts @@ -22,6 +22,7 @@ export class SeriesSizes { private scrollItems: SeriesSizeItem[] = []; private positions: number[] = []; private scrollIndexes: number[] = []; + private modelIndexes: number[] = []; private frozenItems: SeriesSizeItem[] = []; public get scrollCount(): number { @@ -96,6 +97,11 @@ export class SeriesSizes { this.frozenItems.push(item); lastpos += size; } + + this.modelIndexes = _.range(0, this.count); + if (this.hiddenAndFrozenModelIndexes) { + this.modelIndexes = this.modelIndexes.filter(col => !this.hiddenAndFrozenModelIndexes.includes(col)); + } } public getScrollIndexOnPosition(position: number): number { @@ -303,27 +309,32 @@ export class SeriesSizes { this.buildIndex(); } public realToModel(realIndex: number): number { - if (this.hiddenAndFrozenModelIndexes == null && this.frozenModelIndexes == null) return realIndex; - if (realIndex < 0) return -1; - if (realIndex < this.frozenCount && this.frozenModelIndexes != null) return this.frozenModelIndexes[realIndex]; - if (this.hiddenAndFrozenModelIndexes == null) return realIndex; - realIndex -= this.frozenCount; - for (let hidItem of this.hiddenAndFrozenModelIndexes) { - if (realIndex < hidItem) return realIndex; - realIndex++; - } - return realIndex; + return this.modelIndexes[realIndex] ?? -1; + // console.log('realToModel', realIndex); + // if (this.hiddenAndFrozenModelIndexes == null && this.frozenModelIndexes == null) return realIndex; + // if (realIndex < 0) return -1; + // if (realIndex < this.frozenCount && this.frozenModelIndexes != null) return this.frozenModelIndexes[realIndex]; + // if (this.hiddenAndFrozenModelIndexes == null) return realIndex; + // realIndex -= this.frozenCount; + // console.log('this.hiddenAndFrozenModelIndexes', this.hiddenAndFrozenModelIndexes); + // for (let hidItem of this.hiddenAndFrozenModelIndexes) { + // if (realIndex < hidItem) return realIndex; + // realIndex++; + // } + // console.log('realToModel RESP', realIndex); + // return realIndex; } public modelToReal(modelIndex: number): number { - if (this.hiddenAndFrozenModelIndexes == null && this.frozenModelIndexes == null) return modelIndex; - if (modelIndex < 0) return -1; - let frozenIndex: number = this.frozenModelIndexes != null ? _.indexOf(this.frozenModelIndexes, modelIndex) : -1; - if (frozenIndex >= 0) return frozenIndex; - if (this.hiddenAndFrozenModelIndexes == null) return modelIndex; - let hiddenIndex: number = _.sortedIndex(this.hiddenAndFrozenModelIndexes, modelIndex); - if (this.hiddenAndFrozenModelIndexes[hiddenIndex] == modelIndex) return -1; - if (hiddenIndex >= 0) return modelIndex - hiddenIndex + this.frozenCount; - return modelIndex; + return this.modelIndexes.indexOf(modelIndex); + // if (this.hiddenAndFrozenModelIndexes == null && this.frozenModelIndexes == null) return modelIndex; + // if (modelIndex < 0) return -1; + // let frozenIndex: number = this.frozenModelIndexes != null ? _.indexOf(this.frozenModelIndexes, modelIndex) : -1; + // if (frozenIndex >= 0) return frozenIndex; + // if (this.hiddenAndFrozenModelIndexes == null) return modelIndex; + // let hiddenIndex: number = _.sortedIndex(this.hiddenAndFrozenModelIndexes, modelIndex); + // if (this.hiddenAndFrozenModelIndexes[hiddenIndex] == modelIndex) return -1; + // if (hiddenIndex >= 0) return modelIndex - hiddenIndex + this.frozenCount; + // return modelIndex; } public getFrozenPosition(frozenIndex: number): number { return this.frozenItems[frozenIndex].position;