Recently I've been using bootstrap-vue and found it a joy to build UI components with Vue.
One thing I needed was a columns picker. I had a table with lots of columns, and don't want to show all columns at once. User can customize the views themselves with this old-style UI.
The design is to have a columns picker like the one shown below. Users can choose which columns to show on the table.
Editing the table columns is a one-off task. Doing so shouldn't need to leave the current page. After the configuration step, users can see the updated table. At the end, I made it as a modal.
The component is a special \<b-modal> that we can trigger with a button.
The component takes in two column arrays which represent:
the current columns
all the available columns for picking
Modal has two built-in custom events @show and @ok that we can listen and prepare rendering the two columns selectors
When users click the apply button, the widget emits an @apply event and the parent component can handle it accordingly.
To make the component test friendly, I added :static="true" to the b-modal. This renders the modal content in-place in the DOM instead of appending it to the body. With this, the jest test can examine the content and make assertions.
The current UI uses two multi-select components from bootstrap. And it doesn't support reordering the selection easily. If you need reordering, consider using the two-list vue-draggable.
P.S. I tried to follow the instructions and publish this as an NPM package. But I didn't get the bootstrap-vue dependency to work nicely with rollup. If you have done it before or have thoughts, feel free to drop me a note!
Building A Bootstrap-Vue table columns picker
Recently I've been using bootstrap-vue and found it a joy to build UI components with Vue.
One thing I needed was a columns picker. I had a table with lots of columns, and don't want to show all columns at once. User can customize the views themselves with this old-style UI.
The design is to have a columns picker like the one shown below. Users can choose which columns to show on the table.
Editing the table columns is a one-off task. Doing so shouldn't need to leave the current page. After the configuration step, users can see the updated table. At the end, I made it as a modal.
I used the \<b-modal> together with \<b-select>.
The core part of the code is like below:
To use this component, you can do:
Some explanations:
@show
and@ok
that we can listen and prepare rendering the two columns selectorsapply
button, the widget emits an@apply
event and the parent component can handle it accordingly.:static="true"
to theb-modal
. This renders the modal content in-place in the DOM instead of appending it to the body. With this, the jest test can examine the content and make assertions.The rest of the logic is available in this repo: https://github.com/junjizhi/btable-columns-picker
P.S. I tried to follow the instructions and publish this as an NPM package. But I didn't get the
bootstrap-vue
dependency to work nicely withrollup
. If you have done it before or have thoughts, feel free to drop me a note!