diff --git a/packages/vtable/examples/menu.ts b/packages/vtable/examples/menu.ts index c88fc81cf..c44be4a06 100644 --- a/packages/vtable/examples/menu.ts +++ b/packages/vtable/examples/menu.ts @@ -906,6 +906,14 @@ export const menus = [ { path: 'unit-test-demo', name: 'pivotTable-size-legend' + }, + { + path: 'unit-test-demo', + name: 'unit-listTable-sort' + }, + { + path: 'unit-test-demo', + name: 'unit-listTable-frozen' } ] }, diff --git a/packages/vtable/examples/unit-test-demo/unit-listTable-frozen.ts b/packages/vtable/examples/unit-test-demo/unit-listTable-frozen.ts new file mode 100644 index 000000000..3f17ff46a --- /dev/null +++ b/packages/vtable/examples/unit-test-demo/unit-listTable-frozen.ts @@ -0,0 +1,96 @@ +import * as VTable from '../../src'; +import records from './marketsales.json'; +const ListTable = VTable.ListTable; +const CONTAINER_ID = 'vTable'; +export function createTable() { + const containerDom: HTMLElement = document.getElementById(CONTAINER_ID) as HTMLElement; + // containerDom.style.position = 'relative'; + containerDom.style.width = '1000px'; + containerDom.style.height = '800px'; + + const columns = [ + { + field: '订单 ID', + caption: '订单 ID', + sort: true, + width: 'auto', + description: '这是订单的描述信息', + style: { + fontFamily: 'Arial', + fontSize: 14 + } + }, + { + field: '订单日期', + caption: '订单日期' + }, + { + field: '发货日期', + caption: '发货日期' + }, + { + field: '客户名称', + caption: '客户名称', + style: { + padding: [10, 0, 10, 60] + } + }, + { + field: '邮寄方式', + caption: '邮寄方式' + }, + { + field: '省/自治区', + caption: '省/自治区' + }, + { + field: '产品名称', + caption: '产品名称' + }, + { + field: '类别', + caption: '类别' + }, + { + field: '子类别', + caption: '子类别' + }, + { + field: '销售额', + caption: '销售额' + }, + { + field: '数量', + caption: '数量' + }, + { + field: '折扣', + caption: '折扣' + }, + { + field: '利润', + caption: '利润' + } + ]; + const option = { + columns, + defaultColWidth: 150, + allowFrozenColCount: 5, + frozenColCount: 2 + }; + option.container = containerDom; + option.records = records; + const tableInstance = new ListTable(option); + + window.tableInstance = tableInstance; + + setTimeout(() => { + console.log(tableInstance.frozenColCount); + }, 3000); + + setTimeout(() => { + tableInstance.frozenColCount = 4; + console.log(tableInstance.frozenColCount); + tableInstance.release(); + }, 6000); +} diff --git a/packages/vtable/examples/unit-test-demo/unit-listTable-sort.ts b/packages/vtable/examples/unit-test-demo/unit-listTable-sort.ts new file mode 100644 index 000000000..7101cc96e --- /dev/null +++ b/packages/vtable/examples/unit-test-demo/unit-listTable-sort.ts @@ -0,0 +1,94 @@ +import * as VTable from '../../src'; +import records from './marketsales.json'; +const ListTable = VTable.ListTable; +const CONTAINER_ID = 'vTable'; +export function createTable() { + const containerDom: HTMLElement = document.getElementById(CONTAINER_ID) as HTMLElement; + // containerDom.style.position = 'relative'; + containerDom.style.width = '1000px'; + containerDom.style.height = '800px'; + + const columns = [ + { + field: '订单 ID', + caption: '订单 ID', + sort: true, + width: 'auto', + description: '这是订单的描述信息', + style: { + fontFamily: 'Arial', + fontSize: 14 + } + }, + { + field: '订单日期', + caption: '订单日期' + }, + { + field: '发货日期', + caption: '发货日期' + }, + { + field: '客户名称', + caption: '客户名称', + style: { + padding: [10, 0, 10, 60] + } + }, + { + field: '邮寄方式', + caption: '邮寄方式' + }, + { + field: '省/自治区', + caption: '省/自治区' + }, + { + field: '产品名称', + caption: '产品名称' + }, + { + field: '类别', + caption: '类别' + }, + { + field: '子类别', + caption: '子类别' + }, + { + field: '销售额', + caption: '销售额' + }, + { + field: '数量', + caption: '数量' + }, + { + field: '折扣', + caption: '折扣' + }, + { + field: '利润', + caption: '利润' + } + ]; + const option = { + columns, + defaultColWidth: 150, + allowFrozenColCount: 5, + sortState: { + field: '订单 ID', + order: 'desc' + } + }; + + option.container = containerDom; + option.records = records; + const tableInstance = new ListTable(option); + + window.tableInstance = tableInstance; + + setTimeout(() => { + console.log(tableInstance.getCellValue(6, 3)); + }, 3000); +} diff --git a/packages/vtable/src/core/BaseTable.ts b/packages/vtable/src/core/BaseTable.ts index 1c60528f0..63d7c2a3b 100644 --- a/packages/vtable/src/core/BaseTable.ts +++ b/packages/vtable/src/core/BaseTable.ts @@ -1011,7 +1011,7 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI { // : this.internalProps.defaultRowHeight) // ); if (isValid(this.rowHeightsMap.get(row))) { - if (this.options._disableColumnAndRowSizeRound) { + if (this.options._disableColumnAndRowSizeRound ?? true) { const height = this.rowHeightsMap.get(row); let heightRange; if (row < this.frozenRowCount) { @@ -1129,7 +1129,7 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI { h += this.getRowHeight(i); } } else { - if (this.options._disableColumnAndRowSizeRound) { + if (this.options._disableColumnAndRowSizeRound ?? true) { for (let i = startRow; i <= endRow; i++) { h += this.getRowHeight(i); }