Skip to content

TablePro

The SearchTable component includes form, table, and pagination components

Basic Usage

vue
vue
<template>
  <TablePro
    v-model="queryParams"
    :form-config="formConfig"
    :columns="columns"
    :table-data="tableData"
    :total="total"
    :loading="loading"
    :row-key="(row) => row.id"
    @query="getList"
    @reset="getList"
  />
</template>

<script lang="ts" setup>
/** Query parameters */
const queryParams = ref<DemoFormModel>({});

const loading = ref(false); // Loading state
const tableData = ref<User.VO[]>([]); // Table data
const total = ref<number>(0); // Total number of table data

/** Get table data */
const getList = async () => {
  try {
    loading.value = true;
    const { data } = await getUserList(queryParams.value);
    tableData.value = data.list;
    total.value = data.total;
  } finally {
    loading.value = false;
  }
};

/** Search form configuration */
const formConfig: FormPro.FormItemConfig[] = [
  { name: "username", label: "Username" },
  { name: "nickname", label: "Nickname" },
];

/** Table column configuration */
const columns = ref<DataTableColumns<User.VO>>([
  { title: "Username", key: "username", align: "center" },
  { title: "Nickname", key: "nickname", align: "center" },
  // ......
]);
</script>

Do not pass the v-model and form-config properties.

No Pagination

Do not pass the total property.

Form Configuration

If the default form configuration does not meet your needs, you can use the form property for configuration. For example, to set the label width, add validation, etc.

💡 Note

If you want to configure form properties individually, move the original :form-config="formConfig" into form and use config instead.

vue
vue
<template>
  <TablePro
    v-model="queryParams"
    :form="{
      config: formConfig,
      props: { rules, labelWidth: 100 },
    }"
    :columns="columns"
    :table-data="tableData"
    :total="total"
    :loading="loading"
    :row-key="(row) => row.id"
    @query="getList"
    @reset="getList"
  />
</template>

<script lang="ts" setup>
const rules = {
  // Fields to validate
};
</script>

Props

NameTypeRequiredDefaultDescription
v-model or model-valueobjectNoSearch parameters
form-configFormItemConfig[]NoSearch form item configuration
columnscolumnsNo[]Columns to display
table-datadataNo[]Data to display
totalnumberNo0Total number of data
loadingbooleanNofalseLoading state
row-keyrow-keyNoundefinedUnique row identifier
table-propsDataTable PropsNo{}Additional table properties
show-tablebooleanNotrueWhether to show the table
operation-spannumberNo4Operation column grid width
operation-button-positionleft, rightNorightOperation button position
pagination-positionleft, center, rightNoleftPagination position
collapse-rowsnumberNo3Collapse search item breakpoint
formFormPro PropsNo{}Form configuration options

💡 Note

  • table-props accepts all DataTable Props except data columns striped single-column single-line
  • operation-span sets the grid width of the operation buttons, default is 4. Usually, you don't need to set it manually, as it will be automatically calculated based on the length of form-config.
  • operation-button-position sets the position of the operation column. If set to left, the operation column will be displayed next to the search items. If set to right, it will be displayed at the far right.
  • collapse-rows is the breakpoint for collapsing search items. Default is 3, meaning if the number of search items is less than 3, the expand/collapse button will not be shown.
  • form is the form configuration option. If the default form configuration does not meet your needs, you can use this property to customize the form configuration. If you set this property, please move the original form-config into form and use config instead.

FormPro Props

NameTypeRequiredDefaultDescription
configSame as FormPro's form-configNo[]Form configuration
propsSame as FormPro's form-propsNo{}Form properties
grid-propsSame as FormPro's grid-propsNo{}Form layout properties
positive-textstringNosee belowConfirm button text
negative-textstringNosee belowCancel button text
  • In the TablePro component, positive-text defaults to Search, negative-text defaults to Reset.
  • In the DrawerForm and ModalForm components, positive-text defaults to Submit, negative-text defaults to Cancel.

Slots

NameParamsDescription
before()Content before the form search button
after()Content after the form search button
controls()Table operation area content

Events

NameTypeDescription
query(val) => voidTrigger search
reset(val) => voidReset form

Contributors

Changelog

Released under the MIT License