AdaptTable for Element Plus

Column management in Element Plus

Everything a user expects to do to a column, without writing a column-settings panel: rename, show and hide, reorder by drag, pin to either edge, resize by drag or keyboard, and switch row density.

Pinning is logical rather than physical, so a column pinned to the start stays on the correct side in a right-to-left layout.

The arrangement is state like any other: persist it to the URL, to localStorage, or to your own server through columnLayout and onColumnLayoutChange.

The code

<script setup lang="ts">
import { ref } from "vue";
import type { ColumnDef, ColumnLayoutState } from "@adapttable/vue";
import { DataTable } from "@adapttable/element-plus";
import { columnMenu } from "@adapttable/element-plus/column-menu";
import { resizableColumns } from "@adapttable/element-plus/resizable-columns";

defineProps<{
  rows: readonly Person[];
  columns: readonly ColumnDef<Person>[];
}>();

const rowKey = (row: Person) => row.id;
const layout = ref<ColumnLayoutState>({
  hidden: [], order: [], widths: {}, pinned: { name: "start" },
});
const features = [columnMenu(), resizableColumns()];
</script>

<template>
  <DataTable
    v-model:column-layout="layout"
    :data="rows" :columns="columns" :row-key="rowKey" :features="features"
  />
</template>

Install

pnpm add @adapttable/element-plus @adapttable/vue @adapttable/core element-plus

The same feature in the other kits

More Element Plus features

Reference: column-management, columns. More of this kit: AdaptTable for Element Plus, or the live demo.