Custom Template
Build your own UI
when using this advanced feature please take extra care not to break any existing functionality (e.g do not remove events or essential attributes like value or ref)
As of version 2 the package offers the ability to seamlessly swap any table component with your own UI implementation.
Usage
Swapped components are declared as the fifth argument you pass when registering the component:
Vue.use(ClientTable, [options = {}], [useVuex = false], [theme = 'bootstrap3'], {
[componentAKey]: ComponentA,
[componentBKey]: ComponentB,
//etc...
});Each component has its current template stored in the Github repo under the templates folder. All components have a single props prop, which is an object containing all contextual data needed to build the component. More on this in the examples section. The full structure of the components tree, along with the corresponding keys is listed below:
VtDataTable: dataTable
VtGenericFilter: genericFilter
VtPerPageSelector: perPageSelector
VtDropdownPagination: dropdownPagination
VtColumnsDropdown: columnsDropdown
VtTable: table
VtTableHead: tableHead
VtHeadingsRow: headingsRow
VtTableHeading: tableHeading
VtSortControl: sortControl
VtFiltersRow: filtersRow
VtTextFilter: textFilter
VtListFilter: listFilter
VtDateFilter: dateFilter
VtTableBody: tableBody
VtNoResultsRow: noResultsRow
VtTableRow: tableRow
VtTableCell: tableCell
VtChildRowToggler: childRowToggler
VtChildRow: childRow
VtGroupRow: groupRow
VtPagination: pagination
Users of premium version, use the template folder of the private repository instead(node_modules/vue-tables-2/templates),as there might be some differences in some of the templates
Examples
Custom Pagination
Let's swap the default pagination, which uses vue-pagination-2, with some other 3rd party implementaion, say vue-plain-pagination .
Copy the existing pagination template:
Modify it like so, and save to your project:
MyPagination.vue
Register it:
Et Voila!
Font Awesome Sort Icon
Let's use vue-fontawesome
Install the icons:
Copy the original template:
Modify and save to your project:
MySortControl.vue
Register it:
Footer Pagination
In this example we will reposition the pagination element inside the table by moving it from VtDataTable to VtTable:
Remove pagination from VtDataTable:
MyDataTable.vue
Add pagination to VtTable:
MyTable.vue
Register Components:
Footer Headings
Add vtHeadingsRow to vtTable:
MyTable.vue
Register the component:
Numeric Field Pagination
Say you have a huge number of pages in your server table, which prevents you from using dropdown pagination due to memory limitations. Let's replace dropdown pagination (VtDropdownPagination) with a numeric field.
NumericFieldPagination.vue
Register the component:
Select2 List Filter
Replace VtListFilter with the following:
Register the component:
Vuetify
This is NOT a complete example. It's what I used recently for a project I was working on, and can serve as a solid starting point for further modifications.
VtDataTable:
VtTable:
VtPagination:
VtPerPageSelector:
VtGenericFilter (remove label):
VtSortControl:
Register the components:
Filter on button click
By default, the generic filter is triggered on key up. Here is how to trigger it on click instead:
VtGenericFilter.vue:
Register the component:
Last updated
Was this helpful?