vue2-bootstrap-table
vue-bootstrap-table is a sortable and searchable table, with Bootstrap styling, for Vue.js.
Features
- Sortable
- Multicolumn Sorting
- Searchable
- Select display columns
- Pagination
- On Table Editing
- Remote data loading
- Remote data processing
Requirements
- Vue 2.* (tested with 2.3.3)
- Bootstrap 3 css
Installation
Install the vue-bootstrap-table package package using npm:
npm install vue2-bootstrap-table2
Or add the js script to your html (download from releases):
<script src="vue-bootstrap-table.js"></script>
Usage
Configuration Props
Column Array Definition
The columns
array takes object of type:
Column Definition Examples
Column with Title "Id" , which is visible but not editable:
Column with Title "Name" , which is visible and editable:
Render Function Example
For a Column definition like so:
There must be a javascript function called renderTestColumn
:
ROW Click Handler
To add a Row click handler function:
On your Vue instance :
And have the javascript function declared like so:
Where event in the MouseEvent
and entry
e the complete entry corresponding to the row.
DEFAULT Ordering
To setup your default ordering for the table:
On your Vue instance :
This will make the default column order be :
- column: name
- order: ascending
AJAX Configuration
Ajax Object properties:
- enabled : to enable loading through ajax call, enable this
- url: the URL where to request the data
- methods: GET and POST are the valid methods allowed
- delegate: False = just get all the data and do processing on browser; True = Ask for data as needed, and all processing is done on the server side.
- axiosConfig: check Axios Page for information regarding Method Config.
Example AJAX config for Remote Loading
This configuration will only make one request to the server, to get all the data and load it straight into the browser.
Example AJAX config for Remote Processing
This configuration will only make many requests to the server, each time data ir needed, or any processing is required: for filtering, ordering, pagniation, changes of page size, etc.
Ajax Request and Expected Response
Ajax Request Parameters Sent
When Ajax is enabled, the following parameters are sent with each request for the URL specified:
sortcol
: Array of String columns to sort (only sent whendelegate
is true, otherwise will be null)sortdir
: Array of sorting directions for each column on sortcol, "ASC" or "DESC" (only sent whendelegate
is true, otherwise will be null)filter
: The filter to be used (only sent whendelegate
is true, otherwise will be null)page
: The number of the page being requested ( when delegate is false, it will always be 1 )pagesize
: The number of records being requested.echo
: A unique number for the request.
When using GET
sortcol
: is sent in the following formatsortcol[]=COLNAME&sortcol[]=COLNAME
sortdir
: is sent in the following formatsortdir[]=ASC&sortdir[]=DESC
This is performed automatically by AXIOS
When using POST
sortcol
: is sent in the following formatsortcol[0]=COLNAME ; sortcol[1]=COLNAME;
sortdir
: is sent in the following formatsortdir[0]=ASC ; sortdir[1]=DESC
This is performed automatically by AXIOS
Ajax Expected Response
For all requests, vue-bootstrap-table expects an object of the following type:
Where:
echo
: is the same integer the request provided.filtered
: is the total amount of entries for the request, and is used for paginationdata
: is an Array of Object with the entries.
Example:
Events
cellDataModifiedEvent
- When a cell is edited, ancellDataModifiedEvent
event is dispatched.ajaxLoadedEvent
- When ajax call is executed successfully anajaxLoadedEvent
event is dispatched.ajaxLoadingError
-When ajax call is executed unsuccessfully anajaxLoadingError
event is dispatched.
Handling Events
Contribute
If you have a feature request, please add it as an issue or make a pull request.
TODO List
- [x] Basic table
- [x] Sorting
- [x] Multicolumn Sorting
- [x] Filter
- [x] Column picker
- [x] Pagination
- [x] Editing
- [x] Ajax
- [ ] Responsive
- [ ] Dates sorting
- [ ] Keyboard navigation