MazTable
MazTable is designed to be a reusable data table with advanced features. Pagination, Search, Column Sorting, Row Selection, UI options, Loading and Slots.
Before use it, you should install the MazUi plugin in your project, follow instructions in Getting Started
Key Features
- Pagination (prop
pagination)- The component supports pagination with buttons to go to the first, previous, next, and last page.
- You can display only the pagination elements (input and buttons) and make API calls to your server to get elements by using the prop
paginationwithno-paginate-rows.
- Search (prop
search): It includes a search feature with a search bar where users can enter a query to filter displayed data. You can choose the column where the search will be activated. - Column Sorting (prop:
sortable): Columns are sortable, indicated by arrow icons. Sorting can be activated by clicking on the column header. - Row Selection (prop
select-value="key"): There is a dedicated column for selection with a checkbox for each row. Users can individually or collectively select/deselect rows. - Customizable Page Size: Users can choose the number of items to display per page using a dropdown list.
- Loading Indicator (prop
loading): A loading indicator (MazLoadingBar) is displayed when data is being loaded.
Available models
- v-model:
(string | boolean | number)[] | undefined(list of selected key) - v-model:search-query:
string | undefined - v-model:page:
number - v-model:page-size:
number
Basic usage
You can use MazTable and his child component to build a simple table and enjoy the style.
| # | Lastname | Firstname | Age |
|---|---|---|---|
| 1 | John | Doe | 99 |
| 2 | Doe | John | 30 |
Advanced data table
You can also provide all your data, the table is auto-generated and you can use the features listed on top
v-model="[ "0262672d-7c7a-4d30-866e-edb88b5a5336" ]"
v-model:search-query="undefined"
v-model:page="1"
v-model:page-size="10"
| # | Name | Code | Type | Area | Actions | |
|---|---|---|---|---|---|---|
| 1 | CL | CUP | Europe | |||
| 2 | PL | LEAGUE | England | |||
| 3 | SA | LEAGUE | Italy | |||
| 4 | WC | CUP | World | |||
| 5 | PPL | LEAGUE | Portugal | |||
| 6 | PD | LEAGUE | Spain | |||
| 7 | FL1 | LEAGUE | France | |||
| 8 | EC | CUP | Europe | |||
| 9 | DED | LEAGUE | Netherlands | |||
| 10 | ELC | LEAGUE | England |
Loading
Enable the loading state with the prop loading
| # | Lastname | Firstname | Age |
|---|---|---|---|
| 1 | John | Doe | 99 |
| 2 | Doe | John | 33 |
| 3 | Max | Simth | 66 |
Sizing
Available sizes: 'mini' | 'xs' | 'sm' | 'md' | 'lg' | 'xl'
| # | Lastname | Firstname | Age |
|---|---|---|---|
| 1 | John | Doe | 99 |
| # | Lastname | Firstname | Age |
|---|---|---|---|
| 1 | John | Doe | 99 |
| # | Lastname | Firstname | Age |
|---|---|---|---|
| 1 | John | Doe | 99 |
Types
Property row
The rows property is an array of Row: type Rows = Row[]
type Row = Record<string, any> & {
selected?: boolean
action?: (row: Row) => unknown
classes?: HTMLAttributes['class']
}Property headers
The headers property has type: type Headers = string | HeadersEnriched[]
export interface MazTableHeadersEnriched {
label: string
key?: string
sortable?: boolean
hidden?: boolean
srOnly?: boolean
width?: string
maxWidth?: string
classes?: ThHTMLAttributes['class']
scope?: ThHTMLAttributes['scope']
align?: ThHTMLAttributes['align']
rowspan?: ThHTMLAttributes['rowspan']
colspan?: ThHTMLAttributes['colspan']
headers?: ThHTMLAttributes['headers']
}Props & Events emitted
Props
| Name | Description | Type | Required | Default | Possible values |
|---|---|---|---|---|---|
| table-class | CSS class of the table element | HTMLAttributes['class'] | No | undefined | - |
| table-style | CSS style of the table element | HTMLAttributes['style'] | No | undefined | - |
| model-value | v-model List of selected rows | (string | boolean | number)[] | No | undefined | - |
| size | Size of the table | MazSize | No | 'md' | xl, lg, md, sm, xs, mini |
| input-size | Size of the search inputs | MazSize | No | undefined | xl, lg, md, sm, xs, mini |
| title | Title of the table | string | No | undefined | - |
| headers | Headers of the table | MazTableHeader[] | No | undefined | - |
| sortable | Enable sort feature on all columns | boolean | No | false | - |
| headers-align | Align all headers | string | No | 'left' | - |
| rows | Rows of the table | T[] | No | undefined | - |
| hoverable | Add hover effect on rows | boolean | No | false | - |
| search | Enable search feature in table header | boolean | No | false | - |
| hide-search-in-row | Disable search in rows - useful to filter data yourself or make search request to server | boolean | No | false | - |
| hide-search-by | Disable search by column (remove select input "search by") | boolean | No | false | - |
| search-query | v-model:search-query Search query in input | string | No | undefined | - |
| background-odd | Add background color to odd rows | boolean | No | false | - |
| background-even | Add background color to even rows | boolean | No | false | - |
| elevation | Add shadow to the table | boolean | No | false | - |
| divider | add divider between rows | boolean | No | false | - |
| caption | Caption of the table | string | No | undefined | - |
| caption-side | Caption side | string | No | 'bottom' | top, bottom |
| pagination | Add pagination in table footer | boolean | No | false | - |
| page | v-model:page Current page of pagination | number | No | 1 | - |
| page-size | v-model:page-size Number of items per page | number | No | 20 | - |
| total-pages | Total number of pages | number | No | undefined | - |
| paginate-rows | Don't paginate rows - useful to make pagination request with your server | boolean | No | true | - |
| total-items | Total number of items | number | No | undefined | - |
| loading | Loading state | boolean | No | false | - |
| selectable | Enable selection of rows | boolean | No | false | - |
| selected-key | Enable selection of rows - key of the selected row | string | No | undefined | - |
| table-layout | Table layout | string | No | undefined | auto, fixed |
| color | Color of the component | MazColor | No | 'primary' | - |
| translations | Translations of the table | DeepPartial<MazUiTranslationsNestedSchema['table']> | No | Translations from @maz-ui/translations | - |
| rounded-size | Size radius of the component's border | string | No | 'lg' | none, sm, md, lg, xl, full |
| scrollable | Enable scrollable on table | boolean | No | false | - |
Events
| Event name | Properties | Description |
|---|---|---|
| update:model-value | value (Row | string | number | boolean)[] - List of selected rows (if selectedKey is defined, it will be the value of the selectedKey of the row) | Emitted when a row is selected |
| update:search-query | searchQuery string - Search query | Emitted when entering a value in the search input |
| update:page | page number - Current page | Emitted when the current page of pagination changes |
| update:page-size | pageSize number - Current page size | Emitted when the page size of pagination changes |
Slots
| Name | Description | Bindings |
|---|---|---|
| title | Replace the title of the table | |
| caption | Add caption on top or bottom of the table | |
| thead | Content in thead element | |
| header | Replace column header | header Object - Header datalabel String - Header label |
header-label-${header.key} | Replace column header label | header Object - Header datalabel String - Header label |
| actions-header | Replace text of actions header | |
| default | ||
| select | Replace checkbox component | row Object - Row dataselected Boolean - If selected or not |
| cell | Replace all row cells | row Object - Row datavalue any - Cell value |
cell-${key} | Replace row cells of column | row Object - Row datavalue any - Cell value |
| actions | Add actions column | row Object - Row data |
| no-results | Replace the no results element | |
| no-results-text | replace no results test only |
MazTableCell
Slots
| Name | Description | Bindings |
|---|---|---|
| default |
MazTableRow
Props
| Name | Description | Type | Required |
|---|---|---|---|
| hoverable | Override hoverable of table props | boolean | No |
| is-head | If true, the row is a head row | boolean | No |
Slots
| Name | Description | Bindings |
|---|---|---|
| default |
MazTableTitle
Slots
| Name | Description | Bindings |
|---|---|---|
| default |