Skip to content

LaraJS Table ​

🌟 Introduction ​

We use Element Plus Table and JSX to create the dynamic LaraTable component. This setup allows for easy customization and robust table functionality with dynamic queries and actions.

vue
<script setup lang="ts">
import { useCategoryTables } from "./table.tsx";

const { table } = useCategoryTables();
</script>

<template>
  <LaraTable :table="table"></LaraTable>
</template>

UI Preview

βš™οΈ Table.tsx ​

Here’s the TypeScript code that manages the table logic and setup. It offers full control over sorting, filtering, column management, and API integration.

tsx
export function useCategoryTables() {
  ...
  const table: LaraTableType<Category> = {
    ...
    name: "category",
    actions: {
      getAll: getCategories,
      delete: deleteCategory,
    },
    query: {
      sort: "-id",
      include: [],
      search: {
        column: "name",
      },
      date: {
        column: "categories.updated_at",
      },
    },
    columns: [
      {
        field: "id",
        type: "string",
        width: 80,
        sortable: "custom",
        align: "center",
        headerAlign: "center",
      },
      {
        field: "name",
        sortable: "custom",
        align: "left",
      },
      {
        field: "description",
        sortable: false,
        align: "left",
        template: ({row}) => <div v-sane-html={row.description} />,
      },
      {
        field: "updated_at",
        sortable: "custom",
        align: "center",
        label: t("date.updated_at"),
        template: "date",
      },
    ],
  };

  return {
    table,
  };
}

πŸ“‹ Table Attributes ​

NameDescriptionTypeDefault
nameUsed for integration with i18n and router, providing localization support and route handling for the table.stringβ€”
refA reference to access the LaraTable component directly, allowing interaction and manipulation of the table instance.Ref | nullβ€”
queryThe query object that sends requests to the API, controlling data fetching for the table's content.IQueryβ€”
filtersDefines filters that can be applied to the table, such as search and date filters for more refined data views.Filter[{ template: 'search' }, { template: 'date' }]
actionsAllows you to set actions that can be performed on the table items, such as edit or delete functionality.Action[{ template: 'edit' }, { template: 'delete' }]
propsInherits all props from the Table API, offering full control over the table behavior and appearance.Table API
columnsDefines the columns that will be displayed in the table, specifying the data structure and presentation of each column.Column[]