How to create a sticky header on a simple table in BootstrapVue?
August 14, 2022Hi Friends đź‘‹,
Welcome To SortoutCode! ❤️
To create the add the sticky header on b-table-simple simple table in BootstrapVue.We are passing the sticky-header
as a prop to create the sticky header to b-table-simple
in BootstrapVue.
Today I am going to show you How you create a sticky header in the simple table in bootstrap-vue?
Table of contains
- Install the Bootstrap and BootstrapVue
- Create FirstComponent.vue and import it into App.js
- Passing sticky-header as the props in b-table-simple
Let’s start today’s tutorial let’s check the examples of how to create a sticky header in the simple table in BootstrapVue?
Install the Bootstrap and BootstrapVue
First, we have to install the Vue project, I had installed the vueJS in my system. If you haven’t installed or have any problem with installation you can follow this article, it will show you step by step process of installation. In that article, I had also show you how to install BootstrapVue in your vue.js project step by step.
How to install or configure vue-bootstrap in VueJS?
Create FirstComponent.vue and import it into App.js
Create the new component into src/components/
components folder.the component name is FirstComponent.vue
and import into App.js
file:
App.js
<template>
<div id="app">
<FirstComponent />
</div>
</template>
<script>
import FirstComponent from "./components/FirstComponent.vue";
export default {
name: "App",
components: {
FirstComponent,
},
};
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
Passing sticky-header as the props in b-table-simple
We are going to create the sticky header in the bootstrap-vue table. Using the sticky-header
prop to enable a vertically scrolling table with headers that remain fixed (sticky) as the table body scrolls. Let’s see the code:
FirstComponent.vue
<template>
<div class="hello">
<b-table-simple sticky-header>
<b-thead>
<b-tr>
<b-th>No.</b-th>
<b-th>Website Name</b-th>
<b-th>Website URL</b-th>
<b-th>Website Status</b-th>
</b-tr>
</b-thead>
<b-tbody>
<b-tr>
<b-td>1</b-td>
<b-td>SortoutCode</b-td>
<b-td>https://sortoutcode.com/</b-td>
<b-td>Active</b-td>
</b-tr>
<b-tr>
<b-td>2</b-td>
<b-td>Aguidehub</b-td>
<b-td>https://aguidehub.com/</b-td>
<b-td>Active</b-td>
</b-tr>
<b-tr>
<b-td>3</b-td>
<b-td>Infinitbility</b-td>
<b-td>https://sortoutcode.com/</b-td>
<b-td>Active</b-td>
</b-tr>
<b-tr>
<b-td>3</b-td>
<b-td>SortoutCode</b-td>
<b-td>https://sortoutcode.com/</b-td>
<b-td>Active</b-td>
</b-tr>
<b-tr>
<b-td>4</b-td>
<b-td>SortoutCode</b-td>
<b-td>https://sortoutcode.com/</b-td>
<b-td>Active</b-td>
</b-tr>
<b-tr>
<b-td>5</b-td>
<b-td>SortoutCode</b-td>
<b-td>https://sortoutcode.com/</b-td>
<b-td>Active</b-td>
</b-tr>
<b-tr>
<b-td>6</b-td>
<b-td>SortoutCode</b-td>
<b-td>https://sortoutcode.com/</b-td>
<b-td>Active</b-td>
</b-tr>
<b-tr>
<b-td>7</b-td>
<b-td>SortoutCode</b-td>
<b-td>https://sortoutcode.com/</b-td>
<b-td>Active</b-td>
</b-tr>
<b-tr>
<b-td>8</b-td>
<b-td>SortoutCode</b-td>
<b-td>https://sortoutcode.com/</b-td>
<b-td>Active</b-td>
</b-tr>
<b-tr>
<b-td>9</b-td>
<b-td>SortoutCode</b-td>
<b-td>https://sortoutcode.com/</b-td>
<b-td>Active</b-td>
</b-tr>
<b-tr>
<b-td>10</b-td>
<b-td>SortoutCode</b-td>
<b-td>https://sortoutcode.com/</b-td>
<b-td>Active</b-td>
</b-tr>
<b-tr>
<b-td>11</b-td>
<b-td>SortoutCode</b-td>
<b-td>https://sortoutcode.com/</b-td>
<b-td>Active</b-td>
</b-tr>
<b-tr>
<b-td>12</b-td>
<b-td>SortoutCode</b-td>
<b-td>https://sortoutcode.com/</b-td>
<b-td>Active</b-td>
</b-tr>
<b-tr>
<b-td>13</b-td>
<b-td>SortoutCode</b-td>
<b-td>https://sortoutcode.com/</b-td>
<b-td>Active</b-td>
</b-tr>
<b-tr>
<b-td>14</b-td>
<b-td>SortoutCode</b-td>
<b-td>https://sortoutcode.com/</b-td>
<b-td>Active</b-td>
</b-tr>
<b-tr>
<b-td>15</b-td>
<b-td>SortoutCode</b-td>
<b-td>https://sortoutcode.com/</b-td>
<b-td>Active</b-td>
</b-tr>
</b-tbody>
</b-table-simple>
</div>
</template>
<script>
export default {
name: "FirstComponent",
};
</script>
For now, let’s check the output.
Output

All the best 👍.