vue-bootstrap4-table
vue-bootstrap4-table copied to clipboard
Pre-select rows
It would be nice to be able to not only give the rows information to the table, but also give the already selected rows, to avoid losing that information on a page reload.
Maybe as a new prop, passing only the indexes of the previously selected rows or something like that.
Found a workaround, https://github.com/rubanraj54/vue-bootstrap4-table/issues/82#issuecomment-707314414
I also needed something to dynamically set a selection of rows checked. Searched for hours, tried many things, here is what I came up with following the idea of @Kwaadpepper
- give a ref attribute to your table so you can refer to it by using
this.$refs.vbt
(if vbt is your ref) - get and set the rows array as usual
- then map over the rows and add the appropriate row to the list of selected_items . Your reference needs to have
vbt_id
so make sure you have a counter running. In my data I have isSelected set to 1 if it is part of the selection.
let i = 1, self = this;
self.rows.map( (item) => {
if (item.isSelected==1) {
item.vbt_id = i++;
self.$refs.vbt.addSelectedItem(item);
} else {
item.vbt_id = i++;
}
});
For me that was all I needed to see my selection properly checked.