fix: 修复 InputTable index 显示错误的问题

This commit is contained in:
liaoxuezhi 2021-08-18 01:31:03 +08:00
parent 7f8f6dc8f7
commit 3d9ce28ae9
2 changed files with 29 additions and 8 deletions

View File

@ -548,8 +548,15 @@ export default class FormTable extends React.Component<TableProps, TableState> {
return null;
}
const perPage = this.props.perPage;
const page = this.state.page || 1;
let offset = 0;
if (typeof perPage === 'number' && perPage) {
offset = (page - 1) * perPage;
}
return {
quickEditEnabled: this.state.editIndex === index
quickEditEnabled: this.state.editIndex === index + offset
};
}
@ -670,8 +677,16 @@ export default class FormTable extends React.Component<TableProps, TableState> {
});
btns.push({
children: ({key, rowIndex}: {key: any; rowIndex: number}) =>
this.state.editIndex === rowIndex ? (
children: ({
key,
rowIndex,
offset
}: {
key: any;
rowIndex: number;
offset: number;
}) =>
this.state.editIndex === rowIndex + offset ? (
<Button
classPrefix={ns}
size="sm"
@ -694,8 +709,16 @@ export default class FormTable extends React.Component<TableProps, TableState> {
});
btns.push({
children: ({key, rowIndex}: {key: any; rowIndex: number}) =>
this.state.editIndex === rowIndex ? (
children: ({
key,
rowIndex,
offset
}: {
key: any;
rowIndex: number;
offset: number;
}) =>
this.state.editIndex === rowIndex + offset ? (
<Button
classPrefix={ns}
size="sm"
@ -772,8 +795,7 @@ export default class FormTable extends React.Component<TableProps, TableState> {
label: __('Table.index'),
width: '1%',
children: (props: any) => {
const idx = this.state.items.indexOf(props.data.raw);
return <td>{~idx ? idx + 1 : ''}</td>;
return <td>{props.offset + props.data.index + 1}</td>;
}
});
}

View File

@ -163,7 +163,6 @@ export const Row = types
return createObject(
extendObject((getParent(self, self.depth * 2) as ITableStore).data, {
index: self.index,
raw: self.data,
// todo 以后再支持多层,目前先一层
parent: parent.storeType === Row.name ? parent.data : undefined
}),