-
Notifications
You must be signed in to change notification settings - Fork 310
refactor: optimize table performance and refactor the table #3514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -15,77 +15,126 @@ import { initFilter } from './common' | |||||||||||||||||||||
|
||||||||||||||||||||||
let columnUniqueId = 0 | ||||||||||||||||||||||
|
||||||||||||||||||||||
export const setColumnFormat = (column, props) => (column.format = props.formatConfig) | ||||||||||||||||||||||
|
||||||||||||||||||||||
function setBasicProperty(column, context) { | ||||||||||||||||||||||
column.id = `col_${++columnUniqueId}` | ||||||||||||||||||||||
column.type = context.type | ||||||||||||||||||||||
column.prop = context.prop | ||||||||||||||||||||||
column.rules = context.rules | ||||||||||||||||||||||
column.required = context.required | ||||||||||||||||||||||
column.property = context.field || context.prop | ||||||||||||||||||||||
column.title = context.title | ||||||||||||||||||||||
column.label = context.label | ||||||||||||||||||||||
column.width = context.width | ||||||||||||||||||||||
column.minWidth = context.minWidth | ||||||||||||||||||||||
column.resizable = context.resizable | ||||||||||||||||||||||
column.fixed = context.fixed | ||||||||||||||||||||||
column.align = context.align | ||||||||||||||||||||||
column.headerAlign = context.headerAlign | ||||||||||||||||||||||
column.footerAlign = context.footerAlign | ||||||||||||||||||||||
column.showOverflow = context.showOverflow | ||||||||||||||||||||||
column.showHeaderOverflow = context.showHeaderOverflow | ||||||||||||||||||||||
column.showTip = context.showTip | ||||||||||||||||||||||
column.showHeaderTip = context.showHeaderTip | ||||||||||||||||||||||
column.className = context.class || context.className | ||||||||||||||||||||||
column.headerClassName = context.headerClassName | ||||||||||||||||||||||
column.footerClassName = context.footerClassName | ||||||||||||||||||||||
column.indexMethod = context.indexMethod | ||||||||||||||||||||||
column.formatText = context.formatText | ||||||||||||||||||||||
column.formatValue = context.formatValue | ||||||||||||||||||||||
|
||||||||||||||||||||||
setColumnFormat(column, context) | ||||||||||||||||||||||
|
||||||||||||||||||||||
column.sortable = context.sortable | ||||||||||||||||||||||
column.sortBy = context.sortBy | ||||||||||||||||||||||
column.sortMethod = context.sortMethod | ||||||||||||||||||||||
column.remoteSort = context.remoteSort | ||||||||||||||||||||||
column.filterMultiple = isBoolean(context.filterMultiple) ? context.filterMultiple : true | ||||||||||||||||||||||
column.filterMethod = context.filterMethod | ||||||||||||||||||||||
column.filterRender = context.filterRender | ||||||||||||||||||||||
column.filter = context.filter && initFilter(context.filter) | ||||||||||||||||||||||
column.treeNode = context.treeNode | ||||||||||||||||||||||
column.renderer = context.renderer | ||||||||||||||||||||||
column.editor = context.editor | ||||||||||||||||||||||
column.operationConfig = context.operationConfig | ||||||||||||||||||||||
column.equals = context.equals | ||||||||||||||||||||||
class FixedDetails { | ||||||||||||||||||||||
isLeft: boolean | ||||||||||||||||||||||
isLeftLast: boolean | ||||||||||||||||||||||
isRight: boolean | ||||||||||||||||||||||
isRightFirst: boolean | ||||||||||||||||||||||
left: number | ||||||||||||||||||||||
right: number | ||||||||||||||||||||||
|
||||||||||||||||||||||
constructor(fixedType) { | ||||||||||||||||||||||
this.isLeft = fixedType === 'left' | ||||||||||||||||||||||
this.isLeftLast = false | ||||||||||||||||||||||
this.isRight = fixedType === 'right' | ||||||||||||||||||||||
this.isRightFirst = false | ||||||||||||||||||||||
this.left = 0 | ||||||||||||||||||||||
this.right = 0 | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
getStyle(rightExtra = 0) { | ||||||||||||||||||||||
const { isLeft, left, isRight, right } = this | ||||||||||||||||||||||
|
||||||||||||||||||||||
return { | ||||||||||||||||||||||
left: isLeft ? `${left}px` : undefined, | ||||||||||||||||||||||
right: isRight ? `${right + rightExtra}px` : undefined | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
getClass() { | ||||||||||||||||||||||
const { isLeftLast, isRightFirst } = this | ||||||||||||||||||||||
|
||||||||||||||||||||||
return { | ||||||||||||||||||||||
'fixed-left-last__column': isLeftLast, | ||||||||||||||||||||||
'fixed-right-first__column': isRightFirst | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
function ColumnConfig(context, { renderHeader, renderCell, renderData } = {}, config = {}) { | ||||||||||||||||||||||
// 基本属性 | ||||||||||||||||||||||
setBasicProperty(this, context) | ||||||||||||||||||||||
// 自定义参数 | ||||||||||||||||||||||
this.params = context.params | ||||||||||||||||||||||
// 渲染属性 | ||||||||||||||||||||||
this.visible = true | ||||||||||||||||||||||
this.level = 1 | ||||||||||||||||||||||
this.rowSpan = 1 | ||||||||||||||||||||||
this.colSpan = 1 | ||||||||||||||||||||||
this.order = null | ||||||||||||||||||||||
this.renderWidth = 0 // 表格列最终的宽度,会将多种尺寸(number、%、auto)全部转化为固定的px尺寸 | ||||||||||||||||||||||
this.renderHeight = 0 | ||||||||||||||||||||||
this.resizeWidth = 0 | ||||||||||||||||||||||
this.renderLeft = 0 | ||||||||||||||||||||||
this.model = {} | ||||||||||||||||||||||
this.renderHeader = renderHeader || context.renderHeader | ||||||||||||||||||||||
this.renderCell = renderCell || context.renderCell | ||||||||||||||||||||||
this.renderData = renderData | ||||||||||||||||||||||
this.showIcon = isBoolean(context.showIcon) ? context.showIcon : true | ||||||||||||||||||||||
this.loading = false | ||||||||||||||||||||||
// 单元格插槽,只对 grid 有效 | ||||||||||||||||||||||
this.slots = context.slots | ||||||||||||||||||||||
this.own = context | ||||||||||||||||||||||
this.asyncPrefix = config.constant.asyncPrefix | ||||||||||||||||||||||
class ColumnConfig { | ||||||||||||||||||||||
constructor(context, { renderHeader, renderCell, renderData } = {}, config = {}) { | ||||||||||||||||||||||
// 基本属性 | ||||||||||||||||||||||
this.id = `col_${++columnUniqueId}` | ||||||||||||||||||||||
this.type = context.type | ||||||||||||||||||||||
this.prop = context.prop | ||||||||||||||||||||||
this.rules = context.rules | ||||||||||||||||||||||
this.required = context.required | ||||||||||||||||||||||
this.property = context.field || context.prop | ||||||||||||||||||||||
this.title = context.title | ||||||||||||||||||||||
this.label = context.label | ||||||||||||||||||||||
this.width = context.width | ||||||||||||||||||||||
this.minWidth = context.minWidth | ||||||||||||||||||||||
this.resizable = context.resizable | ||||||||||||||||||||||
|
||||||||||||||||||||||
this._fixed = context.fixed | ||||||||||||||||||||||
this._fixedDetails = context.fixed ? new FixedDetails(context.fixed) : undefined | ||||||||||||||||||||||
|
||||||||||||||||||||||
this.align = context.align | ||||||||||||||||||||||
this.headerAlign = context.headerAlign | ||||||||||||||||||||||
this.footerAlign = context.footerAlign | ||||||||||||||||||||||
this.showOverflow = context.showOverflow | ||||||||||||||||||||||
this.showHeaderOverflow = context.showHeaderOverflow | ||||||||||||||||||||||
this.showTip = context.showTip | ||||||||||||||||||||||
this.showHeaderTip = context.showHeaderTip | ||||||||||||||||||||||
this.className = context.class || context.className | ||||||||||||||||||||||
this.headerClassName = context.headerClassName | ||||||||||||||||||||||
this.footerClassName = context.footerClassName | ||||||||||||||||||||||
this.indexMethod = context.indexMethod | ||||||||||||||||||||||
this.formatText = context.formatText | ||||||||||||||||||||||
this.formatValue = context.formatValue | ||||||||||||||||||||||
this.format = context.formatConfig | ||||||||||||||||||||||
this.sortable = context.sortable | ||||||||||||||||||||||
this.sortBy = context.sortBy | ||||||||||||||||||||||
this.sortMethod = context.sortMethod | ||||||||||||||||||||||
this.remoteSort = context.remoteSort | ||||||||||||||||||||||
this.filterMultiple = isBoolean(context.filterMultiple) ? context.filterMultiple : true | ||||||||||||||||||||||
this.filterMethod = context.filterMethod | ||||||||||||||||||||||
this.filterRender = context.filterRender | ||||||||||||||||||||||
this.filter = context.filter && initFilter(context.filter) | ||||||||||||||||||||||
this.treeNode = context.treeNode | ||||||||||||||||||||||
this.renderer = context.renderer | ||||||||||||||||||||||
this.editor = context.editor | ||||||||||||||||||||||
this.operationConfig = context.operationConfig | ||||||||||||||||||||||
this.equals = context.equals | ||||||||||||||||||||||
|
||||||||||||||||||||||
// 自定义参数 | ||||||||||||||||||||||
this.params = context.params | ||||||||||||||||||||||
|
||||||||||||||||||||||
// 渲染属性 | ||||||||||||||||||||||
this.visible = true | ||||||||||||||||||||||
this.level = 1 | ||||||||||||||||||||||
this.rowSpan = 1 | ||||||||||||||||||||||
this.colSpan = 1 | ||||||||||||||||||||||
this.order = null | ||||||||||||||||||||||
this.renderWidth = 0 | ||||||||||||||||||||||
this.renderHeight = 0 | ||||||||||||||||||||||
this.resizeWidth = 0 | ||||||||||||||||||||||
this.renderLeft = 0 | ||||||||||||||||||||||
this.model = {} | ||||||||||||||||||||||
this.renderHeader = renderHeader || context.renderHeader | ||||||||||||||||||||||
this.renderCell = renderCell || context.renderCell | ||||||||||||||||||||||
this.renderData = renderData | ||||||||||||||||||||||
this.showIcon = isBoolean(context.showIcon) ? context.showIcon : true | ||||||||||||||||||||||
this.loading = false | ||||||||||||||||||||||
|
||||||||||||||||||||||
// 单元格插槽,只对 grid 有效 | ||||||||||||||||||||||
this.slots = context.slots | ||||||||||||||||||||||
this.own = context | ||||||||||||||||||||||
this.asyncPrefix = config.constant.asyncPrefix | ||||||||||||||||||||||
} | ||||||||||||||||||||||
Comment on lines
+120
to
+124
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Null-safety for
- this.asyncPrefix = config.constant.asyncPrefix
+ this.asyncPrefix = config?.constant?.asyncPrefix Either add this guard or assert in the public factory that 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||
|
||||||||||||||||||||||
set fixed(val) { | ||||||||||||||||||||||
this._fixed = val | ||||||||||||||||||||||
this._fixedDetails = val ? new FixedDetails(val) : undefined | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
get fixed() { | ||||||||||||||||||||||
return this._fixed | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
get fixedDetails() { | ||||||||||||||||||||||
return this._fixedDetails | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
export const getColumnConfig = (context, options, config) => | ||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Assertion no longer validates “fixed” behaviour – only text.
The previous test verified the header cell’s
right
style to ensure the column is actually fixed.By switching to a pure text check we lose coverage of the sticky-column behaviour that this demo is supposed to showcase. At minimum, assert that the cell has the expected CSS class (
col__fixed
) or computed style (position: sticky
,left/right
offset), e.g.:📝 Committable suggestion
🤖 Prompt for AI Agents