Table

The table component is an extension to the default HTML table, featuring: column visibility controls, pagination, sorting, loading state, etc

API

Props

NameTypeDefaultDescription
loadingBooleanfalseDefines if the table should be in loading state or not, showing a spinner when this prop is set to true.
selectable-rowsBooleanfalseDefines if the table can allow rows to be selected or not, showing checkboxes on each row when this prop is set to true.
columnsArray[]Array containing the columns that the table component should render.
rowsArray[]Array containing the rows that the table component should render.
local-paginationBooleanfalseDefines if the table should paginate the rows internally or not.
Pages will be calculated based on the page, rows-per-page and total-rows props.
pageNumber0Defines the current page for the table pagination.
rows-per-pageNumber10Defines the maximum number of rows to show by page.
total-rowsNumber0Defines the total number of rows available to paginate through.
local-sortBooleanfalseDefines if the table should sort the rows internally or not.
The sorting will be based on the sort-by and sort-direction props.
sort-byString''Defines the field that is actively being used to sort the table.
sort-directionString'asc'Defines the direction of the sorting applied to the table when sorting by a specific field.
filterableBooleanfalseDefines that the table can have filters.
local-filteringBooleanfalseDefines that the table must filter the rows by itself instead of relying in server-side filtering only.

Columns

PropertyTypeDescription
keyStringKey identifier of the column, used to search for the value in the row object
nameStringName of the column to show in the table header
hiddenBooleanDefines if the column should be hidden or not
sortableBooleanDefines if the column allows sorting

Events

NameDescription
selected-rows-changedEvent emitted whenever a row is selected/un-selected, containing the array of currently selected rows.
update:columnsEvent emitted whenever the table wants to update the columns prop value.
update:pageEvent emitted whenever the table wants to update the page prop value.
update:rows-per-pageEvent emitted whenever the table wants to update the rows-per-page prop value.
update:sort-byEvent emitted whenever the table wants to update the sort-by prop value.
update:sort-directionEvent emitted whenever the table wants to update the sort-direction prop value.
update:filtersEvent emitted whenever the table filters data changed.

Basic Table

# Number
12020_01
22020_02
2 Results
<template>
	<Table v-model:columns="columns" :rows="rows" />
</template>

<script>
export default {
    data() {
        return {
            columns: [...],
            rows: [...],
        }
    },
}
</script>

Loading

# Number
<template>
	<Table v-model:columns="columns" :rows="rows" loading />
</template>

<script>
export default {
    data() {
        return {
            columns: [...],
            rows: [...],
        }
    },
}
</script>

Row Selection

# Number
12020_01
22020_02
2 Results
<template>
	<Table v-model:columns="columns" :rows="rows" selectable-rows />
</template>

<script>
export default {
    data() {
        return {
            columns: [...],
            rows: [...],
        }
    },
}
</script>

Row Selection with actions

# Number
12020_01
22020_02
2 Results
<template>
	<Table v-model:columns="columns" :rows="rows" selectable-rows>
		<template #selection-actions="{ rows }">
			<Button @click="logSelectedRows(rows)"> Log </Button>
		</template>
	</Table>
</template>

<script>
export default {
    data() {
        return {
            columns: [...],
            rows: [...],
        }
    },

    methods: {
        logSelectedRows(rows) {
            console.log(rows)
        }
    }
}
</script>

Pagination

Local pagination

# Name Status Created At
1Test 01Created2022-03-18 01:24:00
2Test 02Created2022-03-18 01:24:00
3Test 03Created2022-03-18 01:24:00
4Test 04Created2022-03-18 01:24:00
5Test 05Created2022-03-18 01:24:00
6Test 06Created2022-03-18 01:24:00
7Test 07Created2022-03-18 01:24:00
8Test 08Created2022-03-18 01:24:00
9Test 09Created2022-03-18 01:24:00
10Test 10Created2022-03-18 01:24:00
1 10 of 21
1 of 3
<template>
	<Table
		v-model:columns="columns"
		v-model:page="page"
		v-model:rows-per-page="rowsPerPage"
		:total-rows="totalRows"
		:rows="rows"
		local-pagination
	/>
</template>

<script>
export default {
    data() {
        return {
            columns: [...],
            rows: [...],
            page: 1,
            rowsPerPage: 10,
            totalRows: 21,
        }
    },
}
</script>

Remote pagination

# Name Status Created At
1 10 of 21
1 of 3
<template>
	<Table
		v-model:columns="columns"
		v-model:page="page"
		v-model:rows-per-page="rowsPerPage"
		:rows="rows"
		:loading="loading"
		:total-rows="totalRows"
	/>
</template>

<script>
export default {
    data() {
        return {
            loading: false,
            columns: [...],
            rows: [...],
            page: 1,
            rowsPerPage: 10,
            totalRows: 21,
        }
    },

    methods: {
        fetchRows(page, limit) {
            this.loading = true
            // Simulate request to get rows
            // Assign those rows to this.rows
            this.loading = false
        },
    },

    watch: {
        page(currentPage) {
            this.fetchRows(currentPage, this.rowsPerPage)
        },
    },

    mounted() {
        this.fetchRows(1, 10)
    },
}
</script>

Sorting

Local Sorting

# Name Status Created At
1Test 01Created2022-03-18 01:24:00
3Test 03Created2022-03-18 01:24:00
4Test 04Created2022-03-18 01:24:00
6Test 06Created2022-03-18 01:24:00
7Test 07Created2022-03-18 01:24:00
8Test 08Created2022-03-18 01:24:00
9Test 09Created2022-03-18 01:24:00
10Test 10Created2022-03-18 01:24:00
11Test 11Created2022-03-18 01:24:00
12Test 12Created2022-03-18 01:24:00
13Test 13Created2022-03-18 01:24:00
14Test 14Created2022-03-18 01:24:00
15Test 15Created2022-03-18 01:24:00
16Test 16Created2022-03-18 01:24:00
17Test 17Created2022-03-18 01:24:00
18Test 18Created2022-03-18 01:24:00
19Test 19Created2022-03-18 01:24:00
2Test 20Created2022-03-18 01:24:00
20Test 20Created2022-03-18 01:24:00
21Test 21Created2022-03-18 01:24:00
5Test 55Created2022-03-18 01:24:00
21 Results
<template>
	<Table
		v-model:columns="columns"
		v-model:sort-by="sortBy"
		v-model:sort-direction="sortDirection"
		:rows="rows"
		local-sort
	/>
</template>

<script>
export default {
    data() {
        return {
            columns: [...],
            rows: [...],
            sortBy: 'name',
            sortDirection: 'asc',
            localSort: true,
        }
    },
}
</script>

Local Sorting and Pagination

# Name Status Created At
1Test 01Created2022-03-18 01:24:00
2Test 20Created2022-03-18 01:24:00
3Test 03Created2022-03-18 01:24:00
4Test 04Created2022-03-18 01:24:00
5Test 55Created2022-03-18 01:24:00
6Test 06Created2022-03-18 01:24:00
7Test 07Created2022-03-18 01:24:00
8Test 08Created2022-03-18 01:24:00
9Test 09Created2022-03-18 01:24:00
10Test 10Created2022-03-18 01:24:00
1 10 of 21
1 of 3
<template>
	<Table
		v-model:columns="columns"
		v-model:sort-by="sortBy"
		v-model:sort-direction="sortDirection"
		v-model:page="page"
		v-model:rows-per-page="rowsPerPage"
		:rows="rows"
		:total-rows="totalRows"
		local-sort
		local-pagination
	/>
</template>

<script>
export default {
    data() {
        return {
            columns: [...],
            rows: [...],
            sortBy: 'id',
            sortDirection: 'asc',
            localSort: true,
            page: 1,
            rowsPerPage: 10,
            totalRows: 21,
        }
    },
}
</script>

Filters

Every table can be filtered, either remotely or locally. For starters, use the filterable prop to identify that the table can be filtered.

Remote filtering

A filterable table, by default, will emit the update:filters event whenever a filter changes. The update:filters event contains the full array of filters applicable. This payload can be used for server-side filtering.

# Number
12020_01
22020_02
2 Results
<template>
	<Table
		v-model:columns="columns"
		:rows="rows"
		:loading="loading"
		filterable
		@update:filters="updateFilters"
	/>
</template>

<script>
export default {
	data() {
		return {
			columns: [...],
			rows: [...],
			loading: false,
			filters: [],
		}
	},

	methods: {
		updateFilters(filters) {
			this.filters = filters
			this.loading = true

			setTimeout(() => {
				// Perform HTTP request here to retrieve the filtered rows
				// from the server, assign them to this.rows and stop loading:
				this.loading = false
			}, 1000)
		},
	},
}
</script>

Local filtering

In cases we don't need to filter the table rows remotely, we can use the local-filtering prop to make the table component filter the rows locally.

# Name Status Created At
1Test 01Created2022-03-18 01:24:00
2Test 02Created2022-03-18 01:24:00
3Test 03Created2022-03-18 01:24:00
4Test 04Created2022-03-18 01:24:00
5Test 05Created2022-03-18 01:24:00
6Test 06Created2022-03-18 01:24:00
7Test 07Created2022-03-18 01:24:00
8Test 08Created2022-03-18 01:24:00
9Test 09Created2022-03-18 01:24:00
10Test 10Created2022-03-18 01:24:00
11Test 11Created2022-03-18 01:24:00
12Test 12Created2022-03-18 01:24:00
13Test 13Created2022-03-18 01:24:00
14Test 14Created2022-03-18 01:24:00
15Test 15Created2022-03-18 01:24:00
16Test 16Created2022-03-18 01:24:00
17Test 17Created2022-03-18 01:24:00
18Test 18Created2022-03-18 01:24:00
19Test 19Created2022-03-18 01:24:00
20Test 20Created2022-03-18 01:24:00
21Test 21Created2022-03-18 01:24:00
21 Results
<template>
	<Table v-model:columns="columns" :rows="rows" filterable local-filtering />
</template>

<script>
export default {
	data() {
		return {
			columns: [...],
			rows: [...],
		}
	},
}
</script>
Last Updated:
Contributors: Carlos Pereira