Datatables
Vue Bootstrap 5 Datatables
Vue Datatable is a component which mix tables with advanced options like searching, sorting and pagination.
Note: Read the API tab to find all available options and advanced customization
Basic example - HTML markup
Vue Datatable component can render your data in three ways. In the first one, you simply create a HTML markup for your table inside MDBDatatable component - you can customize your table later by adding props to the component. Some of the more advanced options for columns, described in the Advanced Data Structure section can be also used by setting proper attritube directly to a column (f.e. sort:"false"
).
Vue Datatable collects information from HTML markup to create a data structure - the <table>
element will be replaced in the DOM with a different node after component initializes.
Name | Position | Office | Age | Start date | Salary |
---|---|---|---|---|---|
Tiger Nixon | System Architect | Edinburgh | 61 | 2011/04/25 | $320,800 |
Garrett Winters | Accountant | Tokyo | 63 | 2011/07/25 | $170,750 |
Ashton Cox | Junior Technical Author | San Francisco | 66 | 2009/01/12 | $86,000 |
Cedric Kelly | Senior Javascript Developer | Edinburgh | 22 | 2012/03/29 | $433,060 |
Airi Satou | Accountant | Tokyo | 33 | 2008/11/28 | $162,700 |
Brielle Williamson | Integration Specialist | New York | 61 | 2012/12/02 | $372,000 |
Herrod Chandler | Sales Assistant | San Francisco | 59 | 2012/08/06 | $137,500 |
Rhona Davidson | Integration Specialist | Tokyo | 55 | 2010/10/14 | $327,900 |
Colleen Hurst | Javascript Developer | San Francisco | 39 | 2009/09/15 | $205,500 |
Sonya Frost | Software Engineer | Edinburgh | 23 | 2008/12/13 | $103,600 |
Jena Gaines | Office Manager | London | 30 | 2008/12/19 | $90,560 |
Quinn Flynn | Support Lead | Edinburgh | 22 | 2013/03/03 | $342,000 |
Charde Marshall | Regional Director | San Francisco | 36 | 2008/10/16 | $470,600 |
Haley Kennedy | Senior Marketing Designer | London | 43 | 2012/12/18 | $313,500 |
Basic data structure
The second option is a very basic data structure, where columns are represented by an array of strings and so is each row. The table will match each string in a row to a corresponding index in a columns array. This data structure, as it's based on indexes, not key-value pairs, can be easily used for displaying data from the CSV format.
Advanced data structure
The last and most advanced data structure allows customizing each column (sort, width, fixed, field) and matches values from each row to a column in which the field
equals to a given key value. This data format can be easily used to display JSON data.
You can also use a mixed version, where columns are an array of object and each row is an array of strings.
Search
The search field is not a part of the Datatable - place an MDBInput component on your page and use search
property to filter entries.
Advanced search
When using the searching method, you can specify which columns it should take under consideration - pass an array of fields as searchColumns
property. By default, searching will apply to all columns.
Selectable rows
When the selectable
property is set to true
, user can interact with your table by selecting rows - you can get the selected rows by listening to the selected-rows
emitted event.
Scroll
Setting maximum height/width will enable vertical/horizontal scrolling.
Fixed header
Use the fixedHeader
property to ensure that a table's header is always visible while scrolling.
Fixed columns
Making a column sticky requires setting two options - width and fixed. A first option is a number of pixels, while the other one can be either a true
(in which case the column will stick on the left) or a string right
.
Async data
Loading content asynchronously is an important part of working with data tables - with Vue Datatable you can easily display content after fetching it from API by updating the dataset object. The component watches dataset object and updates on each change. Additionally, setting a loading
option to true
will disable all interactions and display a simple loader while awaiting data.
Cell formatting
Clickable rows
Click on the row to preview the message.
Selecting the row with checkbox doesn't emit the row-click
event.
Note: To prevent this action with other clickable elements within the row, call stopPropagation()
method.
Note: This feature cannot be used simultaneously with edit
option.