Data Table
This component is based on Vue-Tables-2 Refer to source code for additional documentation.
Additional keys:
Additional Keys | Type | Description |
---|---|---|
| string | The key of an array in your data model containing the data to display in the table |
| object | Various options as defined in the source code (see link above) |
| array | (optional) Array of actions to execute when row is clicked |
| array | (optional) Array of objects, allows insertion of HTML content (see below) |
Slots Example
Add the slots
key to this element to define HTML regions to be displayed with the table. The slot
key within each object defines the name of the slot, which can be referenced in the columns
key.
If you name a slot child_row
, that HTML content will be displayed when the row of the table is expanded. (see CSS trick below for how to customize the look of the child row icon)
When referencing row data within slots, use props.row
instead of the usual model
keyword.
Slots
Slots allow you to insert you own custom HTML in predefined positions within the component Slots with respect the BF Forms render engine and render VueJS code also:
beforeTable
: Before the table wrapper. After the controls rowafterTable
: Before the table wrapper.beforeFilter
: Before the global filter (filterByColumn: false
)afterFilter
: After the global filterbeforeLimit
: Before the per page controlafterLimit
: After the per page controlbeforeFilters
: Before the filters row (filterByColumn: true
)afterFilters
: After the filters rowbeforeBody
: Before the<tbody>
tagafterBody
: After the<tbody>
tagprependBody
: Prepend to the<tbody>
tagappendBody
: Append to the<tbody>
tag
If a slot has the same name as a column, it will replace the columns contents. You can class the rows object (data object for that row) via model.row.myField
Accessing Data in slots
row
Each rows data can be found in the props.row
variable when using custom html slots.
eg: {{props.row.nameFirst}}
would render the first name field
data model
Sometimes you may want to reference the parent data model (The model that was used for the form, or the container element). You can reference to parents data model with the variable model
eg: {{model.isLocked}}
would render the isLocked field in the parent data model
Child Rows
Add the following CSS to your site to change how the icon to open or close the child row
Interacting with the Table (Row Click Actions)
actions_onRowClick
The Data Table element supports actions_onRowClick
actions. This allows you to programmatically control what happens when a user clicks a row.
Within each action in this actions array, a "row" key will be injected into the options.params
so that you can reference the data of the row that was clicked.
To access the row from a function action use
action.options.params.row
To access the row from within an options key (see example below), use
this.params.row.id
The following is an example that will pas the key id
from the table row into the path action
This key can be retrieved in the onFormRequest
script as follows:
Custom Sorting Functionality
A common issue arises when attempting to use the table’s custom sorting functionality for columns where numeric values are stored as strings. For instance, when sorting a column with prices stored as strings, the default behavior sorts them alphabetically rather than numerically.
To address this, you can define custom sorting functions in the table options. Below is an example demonstrating how to handle custom sorting for different types of columns:
price_function: Sorts the
price
column numerically, converting the price strings to floats for accurate comparison.name_function: Sorts the
name
column by last name, splitting the full name string and comparing the last names.date_function: Sorts the
date
column chronologically, converting the date strings to date objects for accurate comparison.
Last updated