Skip to content
On this page

Table

Basic table

Child Components

Usage

Import

ts
import { Atable } from "@agufaui/${framework name}";

Html

<atable /> or <Atable />

Configuration

Theme component name: atable

Showcase

records
size: large
Cannot create new record: Duplicate IDs
Display 1-20 of 200 records
id
name
Actions
1Mark
2John
Click to see code
vue
<template>
	<div class="flex items-center flex-wrap flex-col space-y-4">
		<atable
			:panel="tpanel"
			:records-per-page-option="recordsPerPageOption"
			:new-button="newButton"
			:delete-button="deleteButton"
			:show-hide-columns-option="showHideColumnsOption"
			:filters="filters"
			:tag-props="tagProps"
			:alert="alert"
			:pagination="pagination"
			:offset="0"
			:total-records="200"
			show-pages
			if-new
			if-delete
			if-filter
			if-search
		>
			<template #filterPanel>
				<aselectoption v-bind="filterSizeOption">Size</aselectoption>
			</template>
		</atable>
	</div>
</template>

<script lang="ts">
export default {
	name: "DocTable",
};
</script>

<script setup lang="ts">
import {
	TTableHeading,
	IADropdownButtonProps,
	IATpanelProps,
	IASelectoptionProps,
	IADropdownSelectProps,
	IAPaginationProps,
	IAButtonProps,
	TTableFilter,
	IATagProps,
	IAAlertErrorProps,
} from "@agufaui/vue";

const headings: TTableHeading[] = [
	{
		key: "id",
		display: "id",
		field: "id",
	},
	{
		key: "name",
		display: "name",
		field: "name",
		direction: "asc",
	},
	{
		key: "email",
		display: "email",
		field: "email",
		direction: "desc",
	},
];

const items: any[] = [
	{
		id: 1,
		name: "Mark",
		email: "mark@agufa.tech",
	},
	{
		id: 2,
		name: "John",
		email: "john@agufa.tech",
	},
];

const actions: IADropdownButtonProps = {
	itemc: "!bg-red-5 !hover:bg-red-6 !focus:ring-red-5",
	items: [
		{
			display: "Edit",
			event: "edit",
		},
		{
			display: "Delete",
			event: "delete",
		},
	],
};

const tpanel: IATpanelProps = {
	headings,
	items,
	actions,
	multiSelect: true,
	c: "pb-8",
};

const recordsPerPageOption: IASelectoptionProps = {
	options: [
		{ id: 20, name: "20" },
		{ id: 50, name: "50" },
		{ id: 100, name: "100" },
	],
	v: 20,
	vc: "w-5rem",
};

const newButton: IAButtonProps = {
	t: "focus",
	c: "group text-white  bg-gradient-to-br from-green-2 to-green-6 transition-shadow duration-300 hover:via-green-6 focus:(via-green-7 ring-green-5)",
};

const deleteButton: IAButtonProps = {
	c: "h-2.5rem group text-white bg-orange-6 hover:bg-orange-7 focus:ring-orange-5",
};

const showHideColumnsOption: IADropdownSelectProps = {
	items: [
		{ key: "id", value: "id" },
		{ key: "name", value: "name" },
		{ key: "email", value: "email" },
	],
};

const filterSizeOption: IASelectoptionProps = {
	options: [
		{ id: "small", name: "small" },
		{ id: "mid", name: "mid" },
		{ id: "large", name: "large" },
	],
	v: "large",
};

const filters: TTableFilter[] = [{ field: "size", display: "size", displayValue: "large" }];

const tagProps: IATagProps = {
	t: "round",
	c: "text-white bg-gradient-to-br from-blue-2 to-green-5 shadow-md shadow-green-3",
};

const alert: IAAlertErrorProps = {
	show: true,
	error: true,
	v: "Cannot create new record: Duplicate IDs",
};

const pagination: IAPaginationProps = {
	totalPages: 50,
};
</script>

Slot

  • one named slot 'records' for number records per page options label
  • one named slot 'actions' for actions for the table
  • one named slot 'filterPanel' for filters panel

AgufaUI provided Theme

CDefaultType is just string constant "default"

ts
import { CDefaultType, CUseType } from "@agufaui/config";
import type { IATableProps } from "../../types/table/ATable";

export const DATableDefault = {};

export const DATable: Readonly<Record<string, IATableProps>> = {
	[CDefaultType]: DATableDefault,
};

Attributes (Properties)

Default Values

vue

Unique

ts
export type TTableFilter = {
	field: string;
	display: string;
	displayValue: string;
};

export interface IATableProps extends IProps {
	showPages?: boolean;
	recordsPerPageOption?: IASelectoptionProps;
	ifNew?: boolean;
	newButton?: IAButtonProps;
	ifDelete?: boolean;
	deleteButton?: IAButtonProps;
	numSelectedRows?: number;
	showHideColumnsOption?: IADropdownSelectProps;
	ifFilter?: boolean;
	filters?: TTableFilter[];
	tagProps?: IATagProps;
	alert?: IAAlertErrorProps;
	totalRecords?: number;
	offset?: number;
	ifSearch?: boolean;
	panel?: IATpanelProps;
	pagination?: IAPaginationProps;
}

Inherit from IProps

ts
export interface IProps {
	t?: string; // user defined or AgufaUI provided component type.  Not configurable
	c?: string; // css classes for component root html element
}

Events

  • events from Table Panel will be dispatched
  • for action event, TTpanelEmit type field values are:
    • recordsPerPageChange for changing number of records to show per page
    • toggleColumn for hiding or displaying column
    • search for searching
    • searchInput for user typing
    • pageChange when use change page
ts
export interface IATableEmits {
	(e: "action", value: TTpanelEmit): void; // action event
	(e: "ope", value: TTpanelEmit): void; // operation event
	(e: "new", value: MouseEvent): void;
	(e: "delete", value: MouseEvent): void;
	(e: "removeFilter", value: TTableFilter): void;
	(e: "closeAlert", value: MouseEvent): void;
}

Released under the MIT License.