Appearance
NwTable表格组件
基础用法
展开查看
vue
<template>
<div class="example">
<NwTable
:columns="columns"
:data-source="tableData"
title="简单表格"
:showTableSetting="true"
:show-index-column="false"
:rowSelection="{ type: 'radio' }"
:bordered="true"
:actionColumn="actionColumn"
@change="tableChange"
>
<template #expandedRowRender="{ record }">
<span>id: {{ record.id }} </span>
</template>
<!-- <template #tableSearch>
<div>查询表单</div>
</template> -->
<template #bodyCell="{ column }">
<template v-if="column.key === 'action'">
<Button type="link" primary>查看</Button>
<Button type="text" danger>查看</Button>
</template>
</template>
</NwTable>
</div>
</template>
<script setup lang="ts">
const columns = [
{
title: "ID",
dataIndex: "id",
},
{
title: "标题",
dataIndex: "title",
},
{
title: "内容",
dataIndex: "desc",
},
{
title: "数值",
dataIndex: "num",
customRender: ({ record }: { record: any }) => {
return record.num + 1;
},
},
];
const actionColumn = {
width: 260,
title: "操作",
dataIndex: "action",
// slots: { customRender: 'action' },
};
const tableData = (function () {
let lists = [];
for (let i = 0; i < 50; i++) {
lists.push({
id: i,
title: "这是一篇文章" + i,
desc: "好几份送二代更何况的风格" + i,
num: Math.floor(Math.random() * 100),
});
}
return lists;
})();
const tableChange = (e: any) => {
console.log(e);
};
</script>
API
通过设置NwTable的属性可以实现不同的效果。 表格组件的属性说明如下:
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| showTableSetting | 是否显示表格设置 | boolean | true |
| autoCreateKey | 是否自动为每一行数据设置唯一的key | boolean | false |
| striped | 是否展示斑马条纹 | boolean | true |
| api | 远程获取表格数据方法 | function | null |
| beforeFetch | 获取数据之前处理方法 | function | null |
| afterFetch | 获取数据之后处理方法 | function | null |
| immediate | 是否立即请求数据 | boolean | true |
| searchInfo | 额外的请求参数 | object | null |
| fetchSetting | 请求参数配置 | object | {pageField: 'page', sizeField: 'pageSize', listField: 'items',totalField: 'total'} |
| columns | 列配置 | BasicColumn | [] |
| showIndexColumn | 收否展示表格序号 | boolean | true |
| indexColumnProps | 序号列配置 | object | null |
| actionColumn | 操作列 | object | null |
| ellipsis | 超出的是否自动省略 | boolean | true |
| rowSelection | 列表项是否可选择 | Object | null |
| title | 表格标题 | string/function | null |
| dataSource | 表格数据 | array | [] |
| rowKey | 表格行 key 的取值,可以是字符串或一个函数 | string/function | '' |
| bordered | 是否展示表格边框 | boolean | true |
| pagination | 分页信息 | object/boolean | null |
| loading | 表格加载中 | boolean | false |
| rowClassName | 表格行的类名 | function | 无 |
| size | 表格size | string | middle |
column
column和rowSelection 等与ant-design-vue组件大致类似