The default values of the different QTable labels are taken care of by default through Quasar I18n. If your desired language pack is missing, please provide a PR for it.
QTable Vue Properties
Vue Property
Type
Description
data
Array of Objects
Data containing Array of rows to display.
columns
Array of Objects
(Required) Defining each column’s properties.
row-key
String
(Required) Property name of each row defining a unique key for the respective rows.
pagination
Object
Use with .sync. Control of the pagination and sorting. Can enable Table “server-mode” by containing rowsNumber property. See next sections for details.
rows-per-page-options
Array
Array of Numbers representing options for user to select how many rows per page should be shown. Example: ‘[3, 5, 7, 0]’. Notice value 0 means “All”.
selection
String
Set selection mode. One of ‘single’, ‘multiple’ or (default) ‘none’.
selected
Array
Use with .sync. Array of unique keys for selected row(s).
visible-columns
Array
Array of Strings containing the ‘name’ column property value of the visible columns.
loading
Boolean
Show a background process is in progress (like fetching data and so on).
color
String
Color of the default Table controls (pagination, checkboxes, …).
dark
Boolean
When using Table on a dark background.
dense
Boolean
Dense Table, when you want to display more data using the same real estate on window. Gets activated by default on narrow windows.
Sets separator for rows/columns/cell. One of ‘horizontal’, ‘vertical’, ‘cell’, ‘none’.
table-style
String/Array/Object
Style for the <table> tag itself.
table-class
String/Array/Object
Classes for the <table> tag itself.
filter
String
Filter String for Table used by filter-method().
filter-method
Function
When you want a custom filtering method. See next sections for details.
Label properties are by default defined in Quasar’s i18n, but you can override them:
Vue Property
Type
Description
no-data-label
String
Message to display when no rows are available.
no-results-label
String
Message to display when no rows match the filter.
loading-label
String
Message to display when Table currently has no rows but is in the process of fetching them.
selected-rows-label(rowsNumber)
Function
Function that returns a message (String) to display how many rows are selected. Takes a Number parameter which is the actual rows number that are selected.
rows-per-page-label
String
Override ‘Rows per page:’ message.
pagination-label(start,end,total)
Function
Override default ‘x-y of z’ pagination label.
IMPORTANT Initial sorted column, sorting direction & page is configured through the pagination prop. Check the Pagination section below.
Columns Definition
Let’s take an example of configuring columns property. Let’s assume we are telling QTable that row-key is ‘name’.
columns: /* array of Objects */ [ // column Object definition { // unique id (used by row-key, pagination.sortBy, ...) name: 'desc',
// label for header label: 'Dessert (100g serving)',
// row Object property to determine value for this column field: 'name', // OR field: row => row.some.nested.prop
// (optional) if we use visible-columns, this col will always be visible required: true,
// (optional) alignment align: 'left',
// (optional) tell QTable you want this column sortable sortable: true
// (optional) compare function if you have // some custom data or want a specific way to compare two rows sort: (a, b) =>parseInt(a, 10) - parseInt(b, 10) // function return value: // * is less than 0 then sort a to an index lower than b, i.e. a comes first // * is 0 then leave a and b unchanged with respect to each other, but sorted with respect to all different elements // * is greater than 0 then sort b to an index lower than a, i.e. b comes first }, { name: 'calories', label: 'Calories', field: 'calories', sortable: true }, { name: 'fat', label: 'Fat (g)', field: 'fat', sortable: true }, { name: 'carbs', label: 'Carbs (g)', field: 'carbs' }, { name: 'protein', label: 'Protein (g)', field: 'protein' }, { name: 'sodium', label: 'Sodium (mg)', field: 'sodium' }, { name: 'calcium', label: 'Calcium (%)', field: 'calcium', sortable: true, sort: (a, b) =>parseInt(a, 10) - parseInt(b, 10) }, { name: 'iron', label: 'Iron (%)', field: 'iron', sortable: true, sort: (a, b) =>parseInt(a, 10) - parseInt(b, 10) } ]
Pagination
When you want to control Table’s pagination, use pagination prop, but don’t forget to add the .sync modifier:
Gets triggered when using server-side pagination (pagination property Object contains rowsNumber)
Server-side Pagination, Filtering, Sorting
When your database contains a big number of rows for a Table, obviously it’s not feasible to load them all for multiple reasons (memory, UI rendering performance, …). Instead, you can load only a Table page. Whenever the user wants to navigate to another Table page, or wants to sort by a column or wants to filter the Table, a request is sent to the server to fetch the partial data.
First step to enable this behavior is to specify pagination prop, which MUST contain rowsNumber. QTable needs to know the total number of rows available in order to correctly render the pagination links.
Second step is to listen for @request event on QTable. This event is triggered when data needs to be fetched from the server because either page number or sorting or filtering changed.
It’s best that you also specify the loading prop in order to notify the user that a background process is in progress.
The value returned by field is used for sorting rows, while the format value is specifically meant for displaying a value to the user. This is very useful for cases where you need to sort by the initial value of your data. You can (if you want to), however, avoid the format and use custom scoped slots (row, column cell) for defining how Quasar should format the cell(s).
<q-table :data="tableData" :columns="columns" title="Click on a row" dark class="bg-black" color="amber" row-key="name" > <q-trslot="body"slot-scope="props":props="props" @click.native="rowClick(props.row)"class="cursor-pointer"> <q-tdv-for="col in props.cols":key="col.name":props="props"> # {{ col.value }} # </q-td> </q-tr> </q-table>
Custom header (has tooltips)
<q-table :data="tableData" :columns="columns" row-key="name" > <trslot="header"slot-scope="props"> <q-thkey="desc":props="props"> Dessert <q-tooltip>Pick a desert</q-tooltip> </q-th> <q-thkey="calories":props="props"> Calories <q-tooltip>These are the calories</q-tooltip> </q-th> <q-thkey="fat":props="props"> Fat <q-tooltip>This is the fat</q-tooltip> </q-th> <q-thkey="carbs":props="props"> Carbs <q-tooltip>These are the carbohydrates</q-tooltip> </q-th> <q-thkey="protein":props="props"> Protein <q-tooltip>These are the proteins</q-tooltip> </q-th> <q-thkey="sodium":props="props"> Sodium <q-tooltip>This is the sodium</q-tooltip> </q-th> <q-thkey="calcium":props="props"> Calcium <q-tooltip>This is the calcium</q-tooltip> </q-th> <q-thkey="iron":props="props"> Iron <q-tooltip>This is the iron</q-tooltip> </q-th> </tr> </q-table>