Skip to content
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

fix: 修复 #2372 在分页复选框表格中如果跳转到了第n页(n>1),则无法正确勾选默认选中的数据行 #2387

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
18 changes: 16 additions & 2 deletions packages/grid/src/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ export default defineComponent({
tablePage: {
total: 0,
pageSize: GlobalConfig.pager.pageSize || 10,
currentPage: 1
currentPage: 1,
initedPages: {}
}
} as GridReactData<any>)

Expand Down Expand Up @@ -600,7 +601,18 @@ export default defineComponent({
ref: refTable,
key: 'table',
...tableProps,
...tableOns
...tableOns,
onLoadTableData: (params:any) => {
const { tablePage } = reactData
const { currentPage } = tablePage
if (currentPage === 1) return
if (!tablePage.initedPages[currentPage]) {
tablePage.initedPages[currentPage] = true
if (params && typeof params?.handleReLoadDefaults === 'function') {
params.handleReLoadDefaults()
}
}
}
}, slotObj)
]
}
Expand Down Expand Up @@ -783,6 +795,7 @@ export default defineComponent({
}
}
if (isInited) {
tablePage.initedPages = {}
const { computeSortOpts } = $xetable.getComputeMaps()
const sortOpts = computeSortOpts.value
let defaultSort = sortOpts.defaultSort
Expand All @@ -802,6 +815,7 @@ export default defineComponent({
filterList = $xetable.getCheckedFilters()
} else {
if (isReload) {
tablePage.initedPages = {}
$xetable.clearAll()
} else {
sortList = $xetable.getSortColumns()
Expand Down
3 changes: 2 additions & 1 deletion packages/table/src/emits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@ export default [
'cell-area-arrows-start',
'cell-area-arrows-end',
'active-cell-change-start',
'active-cell-change-end'
'active-cell-change-end',
'load-table-data'
] as VxeTableEmits
9 changes: 9 additions & 0 deletions packages/table/src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2384,6 +2384,14 @@ export default defineComponent({
nextTick(() => setTimeout(() => tableMethods.recalculate()))
}

/**
* 当翻页、数据重新加载后 加载默认勾选
*/
const handleReLoadDefaults = () => {
handleDefaultSelectionChecked()
// handleDefaultRadioChecked()
}

/**
* 处理初始化的默认行为
* 只会执行一次
Expand Down Expand Up @@ -6433,6 +6441,7 @@ export default defineComponent({
if (!initStatus) {
handleLoadDefaults()
}
tableMethods.dispatchEvent('load-table-data', { handleReLoadDefaults }, null)
if (!inited) {
handleInitDefaults()
}
Expand Down
1 change: 1 addition & 0 deletions types/grid.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface GridReactData<D = VxeTableDataRow> {
total: number
pageSize: number
currentPage: number
initedPages: Record<string,boolean>
}
}

Expand Down
4 changes: 2 additions & 2 deletions types/table.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2869,8 +2869,8 @@ export type VxeTableEmits = [
'valid-error',
'scroll',
'custom',

...VxeTableProEmits
...VxeTableProEmits,
'load-table-data'
]

export namespace VxeTableDefines {
Expand Down