diff --git a/public/js/components/Stv/Studentenverwaltung.js b/public/js/components/Stv/Studentenverwaltung.js index 111663e47..45fef2e1f 100644 --- a/public/js/components/Stv/Studentenverwaltung.js +++ b/public/js/components/Stv/Studentenverwaltung.js @@ -99,10 +99,9 @@ export default { }, mounted() { if (this.$route.params.id) { - this.$refs.stvList.updateUrl('components/stv/students/uid/' + this.$route.params.id); - } - if (this.$route.params.prestudent_id) { - this.$refs.stvList.updateUrl('components/stv/students/prestudent/' + this.$route.params.prestudent_id); + this.$refs.stvList.updateUrl('components/stv/students/uid/' + this.$route.params.id, true); + } else if (this.$route.params.prestudent_id) { + this.$refs.stvList.updateUrl('components/stv/students/prestudent/' + this.$route.params.prestudent_id, true); } }, diff --git a/public/js/components/Stv/Studentenverwaltung/List.js b/public/js/components/Stv/Studentenverwaltung/List.js index f9ba77213..a150746af 100644 --- a/public/js/components/Stv/Studentenverwaltung/List.js +++ b/public/js/components/Stv/Studentenverwaltung/List.js @@ -60,14 +60,21 @@ export default { layoutColumnsOnNewData: false, height: 'auto', selectable: true, + // TODO(chris): select only one? selectMultiple with click? + index: 'prestudent_id', //persistence: true }, tabulatorEvents: [ { event: 'rowSelectionChanged', handler: this.rowSelectionChanged + }, + { + event: 'dataProcessed', + handler: this.autoSelectRows } - ] + ], + lastSelected: null } }, methods: { @@ -77,7 +84,27 @@ export default { rowSelectionChanged(data) { this.$emit('update:selected', data); }, - updateUrl(url) { + autoSelectRows(data) { + if (this.lastSelected) { + // NOTE(chris): reselect rows on refresh + let selected = this.lastSelected.map(el => this.$refs.table.tabulator.getRow(el.prestudent_id)) + // TODO(chris): unselect current item if it's no longer in the table? + // or maybe reselect only the last one? + selected = selected.filter(el => el); + + this.lastSelected = null; + + if (selected.length) + this.$refs.table.tabulator.selectRow(selected); + } else if(this.lastSelected === undefined) { + // NOTE(chris): select row if it's the only one (preferably only on startup) + if (data.length == 1) { + this.$refs.table.tabulator.selectRow(this.$refs.table.tabulator.getRows()); + } + } + }, + updateUrl(url, first) { + this.lastSelected = first ? undefined : this.selected; if (url) url = CoreRESTClient._generateRouterURI(url); if (!this.$refs.table.tableBuilt) @@ -88,14 +115,6 @@ export default { this.$refs.table.tabulator.setData(url); } }, - mounted() { - this.$refs.table.tabulator.on("dataProcessed", () => { - let rows = this.$refs.table.tabulator.getRows(); - if (rows.length && rows.length == 1) { - this.$refs.table.tabulator.selectRow(); - } - }); - }, template: `