mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-10 17:36:33 +08:00
Merge pull request #7093 from aignatov-bio/ai-sci-10205-preserve-selection-between-pages
Save selection between pages [SCI-10095]
This commit is contained in:
commit
c0e754d184
1 changed files with 45 additions and 30 deletions
|
@ -168,6 +168,7 @@ export default {
|
|||
order: null,
|
||||
totalPage: 0,
|
||||
selectedRows: [],
|
||||
keepSelection: false,
|
||||
searchValue: '',
|
||||
initializing: true,
|
||||
activeFilters: {},
|
||||
|
@ -375,13 +376,13 @@ export default {
|
|||
this.reloadTable();
|
||||
}
|
||||
},
|
||||
reloadTable() {
|
||||
reloadTable(clearSelection = true) {
|
||||
if (this.dataLoading) return;
|
||||
|
||||
this.dataLoading = true;
|
||||
this.selectedRows = [];
|
||||
if (clearSelection) this.selectedRows = [];
|
||||
this.page = 1;
|
||||
this.loadData(true);
|
||||
this.loadData();
|
||||
},
|
||||
loadData(reload = false) {
|
||||
axios
|
||||
|
@ -397,19 +398,25 @@ export default {
|
|||
})
|
||||
.then((response) => {
|
||||
if (reload) {
|
||||
if (this.gridApi) {
|
||||
this.gridApi.setRowData([]);
|
||||
}
|
||||
if (this.gridApi) this.gridApi.setRowData([]);
|
||||
this.rowData = [];
|
||||
}
|
||||
|
||||
if (this.scrollMode === 'pages') {
|
||||
this.selectedRows = [];
|
||||
if (this.gridApi) {
|
||||
this.gridApi.setRowData(this.formatData(response.data.data));
|
||||
}
|
||||
if (this.gridApi) this.gridApi.setRowData(this.formatData(response.data.data));
|
||||
this.rowData = this.formatData(response.data.data);
|
||||
} else {
|
||||
this.handleInfiniteScroll(response);
|
||||
}
|
||||
this.totalPage = response.data.meta.total_pages;
|
||||
this.$emit('tableReloaded');
|
||||
this.dataLoading = false;
|
||||
this.restoreSelection();
|
||||
|
||||
this.handleScroll();
|
||||
});
|
||||
},
|
||||
handleInfiniteScroll(response) {
|
||||
const newRows = this.rowData.slice();
|
||||
this.formatData(response.data.data).forEach((row) => {
|
||||
newRows.push(row);
|
||||
|
@ -424,13 +431,6 @@ export default {
|
|||
});
|
||||
}
|
||||
this.lastPage = !response.data.meta.next_page;
|
||||
}
|
||||
this.totalPage = response.data.meta.total_pages;
|
||||
this.$emit('tableReloaded');
|
||||
this.dataLoading = false;
|
||||
|
||||
this.handleScroll();
|
||||
});
|
||||
},
|
||||
onGridReady(params) {
|
||||
this.gridApi = params.api;
|
||||
|
@ -445,18 +445,18 @@ export default {
|
|||
this.perPage = value;
|
||||
this.page = 1;
|
||||
this.lastPage = false;
|
||||
this.reloadTable();
|
||||
this.reloadTable(false);
|
||||
},
|
||||
setPage(page) {
|
||||
this.page = page;
|
||||
this.loadData();
|
||||
this.loadData(false);
|
||||
},
|
||||
setOrder() {
|
||||
const orderState = this.getOrder(this.columnApi.getColumnState());
|
||||
const [order] = orderState;
|
||||
this.order = order;
|
||||
this.saveTableState();
|
||||
this.reloadTable();
|
||||
this.reloadTable(false);
|
||||
},
|
||||
saveTableState() {
|
||||
const columnsState = this.columnApi ? this.columnApi.getColumnState() : this.tableState?.columnsState || [];
|
||||
|
@ -473,8 +473,23 @@ export default {
|
|||
axios.put(this.userSettingsUrl, { settings: [settings] });
|
||||
this.tableState = tableState;
|
||||
},
|
||||
setSelectedRows() {
|
||||
this.selectedRows = this.gridApi.getSelectedRows();
|
||||
restoreSelection() {
|
||||
if (this.gridApi) {
|
||||
this.gridApi.forEachNode((node) => {
|
||||
if (this.selectedRows.find((row) => row.id === node.data.id)) {
|
||||
node.setSelected(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
setSelectedRows(e) {
|
||||
if (!this.rowData.find((row) => row.id === e.data.id)) return;
|
||||
|
||||
if (e.node.isSelected()) {
|
||||
this.selectedRows.push(e.data);
|
||||
} else {
|
||||
this.selectedRows = this.selectedRows.filter((row) => row.id !== e.data.id);
|
||||
}
|
||||
},
|
||||
emitAction(action) {
|
||||
this.$emit(action.name, action, this.selectedRows);
|
||||
|
@ -535,7 +550,7 @@ export default {
|
|||
dir
|
||||
};
|
||||
this.saveTableState();
|
||||
this.reloadTable();
|
||||
this.reloadTable(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue