Table

Examples

table

namejobfavorite color
1Cy GandertonQuality Control SpecialistBlue
2Hart HagertyDesktop Support TechnicianPurple
3Brice SwyreTax AccountantRed
4Marjy FerenczOffice Assistant ICrimson
export default {
  setup: () => {
    const columns = [
      {
        title: '',
        dataIndex: 'num',
        fixed: 'left',
        width: 20,
      },
      {
        title: 'name',
        dataIndex: 'name',
      },
      {
        title: 'job',
        dataIndex: 'job',
      },
      {
        title: 'favorite color',
        dataIndex: 'favoriteColor',
      },
    ];

    const dataSource = [
      {
        num: 1,
        name: 'Cy Ganderton',
        job: 'Quality Control Specialist',
        favoriteColor: 'Blue',
      },
      {
        num: 2,
        name: 'Hart Hagerty',
        job: 'Desktop Support Technician',
        favoriteColor: 'Purple',
      },
      {
        num: 3,
        name: 'Brice Swyre',
        job: 'Tax Accountant',
        favoriteColor: 'Red',
      },
      {
        num: 4,
        name: 'Marjy Ferencz',
        job: 'Office Assistant I',
        favoriteColor: 'Crimson',
      },
    ];
    return () => (
      <div class="w-full">
        <dv-table columns={columns} dataSource={dataSource} />
      </div>
    );
  },
};
tsx

table-zebra & table-compact

namejobfavorite color
1Cy GandertonQuality Control SpecialistBlue
2Hart HagertyDesktop Support TechnicianPurple
3Brice SwyreTax AccountantRed
4Marjy FerenczOffice Assistant ICrimson
<template>
  <div class="w-full">
    <dv-table :columns="columns" :dataSource="dataSource" zebra compact />
  </div>
</template>

<script lang="tsx">
  export default {
    setup: () => {
      const columns = [
        {
          title: '',
          dataIndex: 'num',
          fixed: 'left',
          width: 20,
        },
        {
          title: 'name',
          dataIndex: 'name',
        },
        {
          title: 'job',
          dataIndex: 'job',
        },
        {
          title: 'favorite color',
          dataIndex: 'favoriteColor',
        },
      ];

      const dataSource = [
        {
          num: 1,
          name: 'Cy Ganderton',
          job: 'Quality Control Specialist',
          favoriteColor: 'Blue',
        },
        {
          num: 2,
          name: 'Hart Hagerty',
          job: 'Desktop Support Technician',
          favoriteColor: 'Purple',
        },
        {
          num: 3,
          name: 'Brice Swyre',
          job: 'Tax Accountant',
          favoriteColor: 'Red',
        },
        {
          num: 4,
          name: 'Marjy Ferencz',
          job: 'Office Assistant I',
          favoriteColor: 'Crimson',
        },
      ];
      return {
        columns,
        dataSource,
      };
    },
  };
</script>
vue

table-jsx

namejobfavorite color
1Cy GandertonQuality Control SpecialistBlue
2Hart HagertyDesktop Support TechnicianPurple
3Brice SwyreTax AccountantRed
4Marjy FerenczOffice Assistant ICrimson
export default {
  setup: () => {
    const columns = [
      {
        title: '',
        dataIndex: 'num',
        fixed: 'left',
        width: 20,
        render: (num) => <strong>{num}</strong>,
      },
      {
        title: 'name',
        dataIndex: 'name',
      },
      {
        title: 'job',
        dataIndex: 'job',
      },
      {
        title: () => (
          <>
            <IconColorPalette size="1.5em" style="margin-right: 6px" />
            favorite color
          </>
        ),
        dataIndex: 'favoriteColor',
        render: (color) => <span style={{ color }}>{color}</span>,
      },
    ];

    const dataSource = [
      {
        num: 1,
        name: 'Cy Ganderton',
        job: 'Quality Control Specialist',
        favoriteColor: 'Blue',
      },
      {
        num: 2,
        name: 'Hart Hagerty',
        job: 'Desktop Support Technician',
        favoriteColor: 'Purple',
      },
      {
        num: 3,
        name: 'Brice Swyre',
        job: 'Tax Accountant',
        favoriteColor: 'Red',
      },
      {
        num: 4,
        name: 'Marjy Ferencz',
        job: 'Office Assistant I',
        favoriteColor: 'Crimson',
      },
    ];
    return () => (
      <div class="w-full">
        <dv-table columns={columns} dataSource={dataSource} />
      </div>
    );
  },
};
tsx

Table

Attributes

namedescriptiontypedefault
columnstable columns configITableColumn[]-
dataSourcetable data sourcearray-
compactmakes table more compactboolean-
zebramakes table rows zebraboolean-

ITableColumn

interface ITableColumn<T = unknown> {
  title?: string | (() => any);
  dataIndex?: string;
  key?: string;
  fixed?: 'left' | 'right';
  render?: (text: string, record: T, index: number) => any;
}