fix(data-grid): placeholder for pending rows in original row number
This commit is contained in:
1 parent
5c66bf5e09
commit
a6696f07ed
2 files changed
+18
-4
No files matched your search
@@ -19,9 +19,19 @@ describe("data grid row number labels", () => {
|
||||
expect(resolveDataGridRowNumberLabel({ displayIndex: 2, sourceIndex: 36, sourceRowNumbers: true, pageOffset: 100 })).toBe("137");
|
||||
});
|
||||
|
||||
it("falls back to the view position for rows without a source index", () => {
|
||||
// 新增行还没有落库位置,sourceIndex 为 undefined
|
||||
expect(resolveDataGridRowNumberLabel({ displayIndex: 7, sourceRowNumbers: true, pageOffset: 0 })).toBe("8");
|
||||
it("uses a placeholder for rows without an original position", () => {
|
||||
// 新增行还没有落库位置(sourceIndex 为 undefined):原始行号模式下用 "+" 占位。
|
||||
// 不能回退到视图序号,否则会与紧随其后的那一行撞号。
|
||||
expect(resolveDataGridRowNumberLabel({ displayIndex: 7, sourceRowNumbers: true, pageOffset: 0 })).toBe("+");
|
||||
expect(resolveDataGridRowNumberLabel({ displayIndex: 7, sourceRowNumbers: true, pageOffset: 100 })).toBe("+");
|
||||
// 视图序号模式不受影响,新增行照常显示它在列表中的位置
|
||||
expect(resolveDataGridRowNumberLabel({ displayIndex: 7, sourceRowNumbers: false, pageOffset: 0 })).toBe("8");
|
||||
});
|
||||
|
||||
it("keeps an inserted row from colliding with the row below it", () => {
|
||||
// 新增行占住显示位置 3(displayIndex 2),紧随其后的原始第 3 行 sourceIndex 为 2
|
||||
expect(resolveDataGridRowNumberLabel({ displayIndex: 2, sourceRowNumbers: true, pageOffset: 0 })).toBe("+");
|
||||
expect(resolveDataGridRowNumberLabel({ displayIndex: 3, sourceIndex: 2, sourceRowNumbers: true, pageOffset: 0 })).toBe("3");
|
||||
});
|
||||
|
||||
it("keeps the draft placeholder regardless of the mode", () => {
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
* 行状态筛选),被隐藏的行后面的行号会整体前移,无法再对应回完整结果里的位置。
|
||||
* `sourceIndex` 是筛选前的原始下标,一直保留在行数据里,因此 `source` 模式直接用它,
|
||||
* 让筛选前后同一个行号始终指向同一条数据。分页模式下原始下标是页内下标,
|
||||
* 仍需叠加页偏移才能得到完整结果中的位置。
|
||||
* 仍需叠加页偏移才能得到完整结果中的位置。未落库的新增行没有原始位置,
|
||||
* 用 "+" 占位(原因见下方函数内注释);草稿行沿用 "*"。
|
||||
*/
|
||||
export interface DataGridRowNumberInput {
|
||||
displayIndex: number;
|
||||
@@ -20,6 +21,9 @@ export interface DataGridRowNumberInput {
|
||||
export function resolveDataGridRowNumberLabel(input: DataGridRowNumberInput): string {
|
||||
// 待保存的草稿行没有落库位置,保持原有的 "*" 占位
|
||||
if (input.isDraft) return "*";
|
||||
// 原始行号模式下,未落库的新增行没有「原始位置」可言。这里用占位符而不是回退到
|
||||
// 视图序号:回退会让它与紧随其后的那一行撞号(插入点之后正好错位 1,两行同号)。
|
||||
if (input.sourceRowNumbers && input.sourceIndex === undefined) return "+";
|
||||
const index = input.sourceRowNumbers && input.sourceIndex !== undefined ? input.sourceIndex : input.displayIndex;
|
||||
return String(index + 1 + input.pageOffset);
|
||||
}
|
||||
Reference in new issue
Block a user