﻿# nf-table {#table}

数据表格，组合搜索表单、分页、列设置、渲染器、操作栏与虚拟滚动。

表格列设置和拖拽列宽使用 IndexedDB（`common-ui-plus` 数据库的 `nf-table` 对象仓库），异步恢复且不回退 localStorage，不自动迁移旧缓存。`clearColumnEditCached()`、`clearDragCached()` 和旧 `*Cookies*` 同步方法支持 `await` 等待完成；IndexedDB 不可用时保留当前实例状态。搜索表单字段设置使用同一数据库中的 `nf-search-form` 对象仓库。

```ts
import NfTable from '@94ai-plus/nf-table'
import type { NfTableColumnAttributes, TableSearchEvent } from '@94ai-plus/nf-table'
import '@94ai-plus/nf-table/style.css'
```

<span id="basic"></span>

<span id="remote"></span>

## 简易配置 {#example-1}

### 简易配置
```vue
<script setup>
import { ref, reactive, h, onBeforeUnmount } from 'vue'
import { ElInput, ElDivider, ElCheckbox, ElPagination, ElTooltip, ElIcon, ElTableColumn, ElForm, ElFormItem } from 'element-plus'
import { QuestionFilled } from '@element-plus/icons-vue'
import { NfTable, NfSearchForm, NfButton, NfEmpty } from '@94ai-plus/common-ui'
const result = ref('')
const showStartTime = ref(false)
const report = (action, row) => result.value = action + (row ? ': ' + row.id : '')
const makeRows = (count, offset = 0) => Array.from({length:count}, (_, i) => ({
  id:offset+i+1, name:'任务'+(offset+i+1), taskId:i%3+1, companyName:'企业'+(i%3+1),
  operationName:'负责人'+(i+1), viceOperationName:'协作人'+(i+1), startTime:'2026-01-01',
  completionRate:i%2?0.6:1, unit:50+i%50, getOptionsId:i%3+1, address:'地址'+(i+1)
}))
const fields = [
  {prop:'normalInputBox',label:'普通输入框',element:'el-input',placeholder:'输入任务名称'},
  {prop:'numberInputBox',label:'数字输入框',element:'el-input-number',placeholder:'输入后搜索即清空数据'},
  {prop:'normalDropdown',label:'普通下拉',element:'el-select',options:[{label:'查询新增10条数据',value:1},{label:'查询数据结果为10条',value:2}]},
  {prop:'virtualDropdown',label:'虚拟下拉',element:'nf-virtual-select',options:[{label:'给点意见',value:'1'},{label:'售后问题',value:'2'}]},
  {prop:'opinion',label:'意见',element:'el-input',placeholder:'根据虚拟下拉显示或隐藏',destory:formData=>formData.virtualDropdown!=='1'},
  {prop:'slotInput',label:'nf-table插槽输入框',slot:'slotInput'},
]
const secondFields = [...fields.filter(field=>!['opinion','slotInput'].includes(field.prop)),
  {prop:'dynamicSlot',label:'从NfSearchForm自定义透传动态slot',slot:'dynamicNfSearchFormSlot'},
  {prop:'repeatCount',label:'测试number-range',element:'number-range',tag:'el-input',initValue:[],limitRange:[1,9999],inputSlot:{append:'repeatCountAppend',doubleAppend:'doubleRepeatCountAppend',doubleSegment:'doubleRepeatCountAppendSegment'}}]
const searchAttrs = {formOptions:fields,btnItems:['search'],columns:4,btnModel:'inline',columnEdit:true}
function useTable(key) {
  const table = ref(), rows = ref(makeRows(20)), allSelected = ref(false)
  const columns = ref([
    {type:'selection',prop:'selection',label:'选择',attr:{width:64,fixed:'left'}},
    {prop:'id',label:'id',labelTooltip:'配置tips',attr:{width:90}},
    {prop:'name',label:'任务名称',attr:{minWidth:160}},
    {prop:'companyName',label:()=>showStartTime.value?'所属企业(右边有日期)':'所属企业(右边无日期)',attr:{minWidth:190}},
    {prop:'startTime',label:'启动日期',destory:()=>!showStartTime.value,attr:{minWidth:150}},
    {prop:'unit',label:'unit数据单位',unit:'%',attr:{minWidth:135}},
    {prop:'taskId',label:'options映射名称',options:[{label:'任务1',value:1,tagType:'success'},{label:'任务2',value:2},{label:'任务3',value:3}],attr:{minWidth:150}},
    {prop:'getOptionsId',label:'getOptions映射名称',getOptions:done=>done([{label:'动态映射1',value:1},{label:'动态映射2',value:2,tagType:'tip'},{label:'动态映射3',value:3}]),attr:{minWidth:190}},
    {prop:'operation',label:'操作',attr:{fixed:'right',minWidth:210},operationSpan:3,operationList:scope=>[
      {name:'详情',onClick:row=>report('详情',row)},
      {name:'编辑',destroy:row=>row.completionRate===1,onClick:row=>report('编辑',row)},
      {name:'语音通知',onClick:row=>report('语音通知',row)},
      {name:'下载',destroy:true,onClick:row=>report('下载',row)},
    ]},
  ])
  const actions = reactive([
    {element:'el-checkbox',value:false,text:'当页全选',events:{change:()=>table.value?.toggleAllSelection()}},
    ...['开启','暂停','删除'].map((text,i)=>({element:'el-button',text,type:i?'danger':'primary',events:{click:()=>report(text)}})),
    {element:'el-button',get text(){return showStartTime.value?'隐藏启动日期':'显示启动日期'},get type(){return showStartTime.value?'danger':'primary'},events:{click:()=>showStartTime.value=!showStartTime.value}},
  ])
  const onSelection = selection => {
    const selected = selection.length > 0 && selection.length === table.value?.showData.length
    allSelected.value = selected; actions[0].value = selected
    result.value = '已选：'+selection.length
  }
  const search = ({data, callback}) => {
    try {
      if (data.numberInputBox) rows.value = []
      else if (data.normalDropdown === 1) rows.value = [...rows.value,...makeRows(10,rows.value.length)]
      else if (data.normalDropdown === 2) rows.value = makeRows(10)
      else rows.value = makeRows(20).filter(row=>row.name.includes(data.normalInputBox || ''))
      result.value = JSON.stringify(data)
    } finally { callback() }
  }
  return {table,rows,columns,actions,allSelected,onSelection,search,key}
}

fields[0] = {...fields[0],label:'必填输入框',rules:[{required:true,message:'请输入',trigger:'blur'}]}
const states = [useTable('first'),useTable('second')]
</script>

<template>
<div class="table-examples">
<div>
<NfTable :ref="value => states[0].table.value = value" :data="states[0].rows.value" :columns="states[0].columns.value"
  :search-form-attrs="{...searchAttrs,formOptions:fields,requiredValidate:true}" :action-bar-opt-list="states[0].actions" :page-attrs="{pageSize:5}"
  :table-attrs="{rowKey:'id',headerCellStyle:({column})=>({background:'var(--el-fill-color-light)',textAlign:column.property==='operation'?'left':'center'}),cellStyle:{textAlign:'center'}}"
  column-edit check-mode="dialog" storage-key="docs-table-1-1-zh" search-form-storage-key="docs-search-table-1-1-zh" :cal-height="false"
  set-easy-conf @search-api="states[0].search" @selection-change="states[0].onSelection">
  <template #slotInput="{formData}"><ElInput v-model="formData.slotInput" clearable /></template>
  <template #dynamicNfSearchFormSlot="{formData}"><ElInput v-model="formData.dynamicSlot" clearable /></template>
  <template #repeatCountAppend>次</template><template #doubleRepeatCountAppend>次</template><template #doubleRepeatCountAppendSegment>至</template>
</NfTable></div>
<ElDivider>上面父容器不限高</ElDivider><ElDivider>下面父容器限高</ElDivider><div class="table-fixed">
<NfTable :ref="value => states[1].table.value = value" :data="states[1].rows.value" :columns="states[1].columns.value"
  :search-form-attrs="{...searchAttrs,formOptions:secondFields,requiredValidate:false}" :action-bar-opt-list="states[1].actions" :page-attrs="{pageSize:5}"
  :table-attrs="{rowKey:'id',headerCellStyle:({column})=>({background:'var(--el-fill-color-light)',textAlign:column.property==='operation'?'left':'center'}),cellStyle:{textAlign:'center'}}"
  column-edit check-mode="dialog" storage-key="docs-table-1-2-zh" search-form-storage-key="docs-search-table-1-2-zh" :cal-height="true"
  set-easy-conf @search-api="states[1].search" @selection-change="states[1].onSelection">
  <template #slotInput="{formData}"><ElInput v-model="formData.slotInput" clearable /></template>
  <template #dynamicNfSearchFormSlot="{formData}"><ElInput v-model="formData.dynamicSlot" clearable /></template>
  <template #repeatCountAppend>次</template><template #doubleRepeatCountAppend>次</template><template #doubleRepeatCountAppendSegment>至</template>
</NfTable></div>

<output aria-live="polite">{{ result }}</output>
</div>
</template>

<style scoped>
.table-examples {max-width:100%;min-width:0}
.table-fixed {height:420px;min-height:0}
.table-examples output {display:block;margin-top:16px;overflow-wrap:anywhere}
.table-examples :deep(.el-divider__text) {max-width:90%;white-space:normal;font-size:12px}
.table-examples :deep(.el-divider--horizontal) {margin:40px 0}
.table-examples :deep(.nf-search-form-control) {max-width:100%}
.table-examples :deep(.el-form--inline) {display:flex;flex-wrap:wrap;gap:0}
@media(max-width:600px){.table-examples :deep(.nf-search-form-item){max-width:100%;margin-right:0}.table-examples :deep(.el-form-item__content){min-width:0}}
</style>
```

## 纯数据定制 {#example-2}

### 纯数据定制
```vue
<script setup>
import { ref, reactive, h, onBeforeUnmount } from 'vue'
import { ElInput, ElDivider, ElCheckbox, ElPagination, ElTooltip, ElIcon, ElTableColumn, ElForm, ElFormItem } from 'element-plus'
import { QuestionFilled } from '@element-plus/icons-vue'
import { NfTable, NfSearchForm, NfButton, NfEmpty } from '@94ai-plus/common-ui'
const result = ref('')
const showStartTime = ref(false)
const report = (action, row) => result.value = action + (row ? ': ' + row.id : '')
const makeRows = (count, offset = 0) => Array.from({length:count}, (_, i) => ({
  id:offset+i+1, name:'任务'+(offset+i+1), taskId:i%3+1, companyName:'企业'+(i%3+1),
  operationName:'负责人'+(i+1), viceOperationName:'协作人'+(i+1), startTime:'2026-01-01',
  completionRate:i%2?0.6:1, unit:50+i%50, getOptionsId:i%3+1, address:'地址'+(i+1)
}))
const fields = [
  {prop:'normalInputBox',label:'普通输入框',element:'el-input',placeholder:'输入任务名称'},
  {prop:'numberInputBox',label:'数字输入框',element:'el-input-number',placeholder:'输入后搜索即清空数据'},
  {prop:'normalDropdown',label:'普通下拉',element:'el-select',options:[{label:'查询新增10条数据',value:1},{label:'查询数据结果为10条',value:2}]},
  {prop:'virtualDropdown',label:'虚拟下拉',element:'nf-virtual-select',options:[{label:'给点意见',value:'1'},{label:'售后问题',value:'2'}]},
  {prop:'opinion',label:'意见',element:'el-input',placeholder:'根据虚拟下拉显示或隐藏',destory:formData=>formData.virtualDropdown!=='1'},
  {prop:'slotInput',label:'nf-table插槽输入框',slot:'slotInput'},
]
const secondFields = [...fields.filter(field=>!['opinion','slotInput'].includes(field.prop)),
  {prop:'dynamicSlot',label:'从NfSearchForm自定义透传动态slot',slot:'dynamicNfSearchFormSlot'},
  {prop:'repeatCount',label:'测试number-range',element:'number-range',tag:'el-input',initValue:[],limitRange:[1,9999],inputSlot:{append:'repeatCountAppend',doubleAppend:'doubleRepeatCountAppend',doubleSegment:'doubleRepeatCountAppendSegment'}}]
const searchAttrs = {formOptions:fields,btnItems:['search'],columns:4,btnModel:'inline',columnEdit:true}
function useTable(key) {
  const table = ref(), rows = ref(makeRows(20)), allSelected = ref(false)
  const columns = ref([
    {type:'selection',prop:'selection',label:'选择',attr:{width:64,fixed:'left'}},
    {prop:'id',label:'id',labelTooltip:'配置tips',attr:{width:90}},
    {prop:'name',label:'任务名称',attr:{minWidth:160}},
    {prop:'companyName',label:()=>showStartTime.value?'所属企业(右边有日期)':'所属企业(右边无日期)',attr:{minWidth:190}},
    {prop:'startTime',label:'启动日期',destory:()=>!showStartTime.value,attr:{minWidth:150}},
    {prop:'unit',label:'unit数据单位',unit:'%',attr:{minWidth:135}},
    {prop:'taskId',label:'options映射名称',options:[{label:'任务1',value:1,tagType:'success'},{label:'任务2',value:2},{label:'任务3',value:3}],attr:{minWidth:150}},
    {prop:'getOptionsId',label:'getOptions映射名称',getOptions:done=>done([{label:'动态映射1',value:1},{label:'动态映射2',value:2,tagType:'tip'},{label:'动态映射3',value:3}]),attr:{minWidth:190}},
    {prop:'operation',label:'操作',attr:{fixed:'right',minWidth:210},operationSpan:3,operationList:scope=>[
      {name:'详情',onClick:row=>report('详情',row)},
      {name:'编辑',destroy:row=>row.completionRate===1,onClick:row=>report('编辑',row)},
      {name:'语音通知',onClick:row=>report('语音通知',row)},
      {name:'下载',destroy:true,onClick:row=>report('下载',row)},
    ]},
  ])
  const actions = reactive([
    {element:'el-checkbox',value:false,text:'当页全选',events:{change:()=>table.value?.toggleAllSelection()}},
    ...['开启','暂停','删除'].map((text,i)=>({element:'el-button',text,type:i?'danger':'primary',events:{click:()=>report(text)}})),
    {element:'el-button',get text(){return showStartTime.value?'隐藏启动日期':'显示启动日期'},get type(){return showStartTime.value?'danger':'primary'},events:{click:()=>showStartTime.value=!showStartTime.value}},
  ])
  const onSelection = selection => {
    const selected = selection.length > 0 && selection.length === table.value?.showData.length
    allSelected.value = selected; actions[0].value = selected
    result.value = '已选：'+selection.length
  }
  const search = ({data, callback}) => {
    try {
      if (data.numberInputBox) rows.value = []
      else if (data.normalDropdown === 1) rows.value = [...rows.value,...makeRows(10,rows.value.length)]
      else if (data.normalDropdown === 2) rows.value = makeRows(10)
      else rows.value = makeRows(20).filter(row=>row.name.includes(data.normalInputBox || ''))
      result.value = JSON.stringify(data)
    } finally { callback() }
  }
  return {table,rows,columns,actions,allSelected,onSelection,search,key}
}

const states = [useTable('first'),useTable('second')]
</script>

<template>
<div class="table-examples">
<div>
<NfTable :ref="value => states[0].table.value = value" :data="states[0].rows.value" :columns="states[0].columns.value"
  :search-form-attrs="{...searchAttrs,formOptions:fields,requiredValidate:false}" :action-bar-opt-list="states[0].actions" :page-attrs="{pageSize:5}"
  :table-attrs="{rowKey:'id',headerCellStyle:({column})=>({background:'var(--el-fill-color-light)',textAlign:column.property==='operation'?'left':'center'}),cellStyle:{textAlign:'center'}}"
  column-edit check-mode="dialog" storage-key="docs-table-2-1-zh" search-form-storage-key="docs-search-table-2-1-zh" :cal-height="false"
  :init-search-api="true" :page-change-search-api="true" @search-api="states[0].search" @selection-change="states[0].onSelection">
  <template #slotInput="{formData}"><ElInput v-model="formData.slotInput" clearable /></template>
  <template #dynamicNfSearchFormSlot="{formData}"><ElInput v-model="formData.dynamicSlot" clearable /></template>
  <template #repeatCountAppend>次</template><template #doubleRepeatCountAppend>次</template><template #doubleRepeatCountAppendSegment>至</template>
</NfTable></div>
<ElDivider>上面父容器不限高</ElDivider><ElDivider>下面父容器限高</ElDivider><div class="table-fixed">
<NfTable :ref="value => states[1].table.value = value" :data="states[1].rows.value" :columns="states[1].columns.value"
  :search-form-attrs="{...searchAttrs,formOptions:secondFields,requiredValidate:false}" :action-bar-opt-list="states[1].actions" :page-attrs="{pageSize:5}"
  :table-attrs="{rowKey:'id',headerCellStyle:({column})=>({background:'var(--el-fill-color-light)',textAlign:column.property==='operation'?'left':'center'}),cellStyle:{textAlign:'center'}}"
  column-edit check-mode="dialog" storage-key="docs-table-2-2-zh" search-form-storage-key="docs-search-table-2-2-zh" :cal-height="true"
  :init-search-api="true" :page-change-search-api="true" @search-api="states[1].search" @selection-change="states[1].onSelection">
  <template #slotInput="{formData}"><ElInput v-model="formData.slotInput" clearable /></template>
  <template #dynamicNfSearchFormSlot="{formData}"><ElInput v-model="formData.dynamicSlot" clearable /></template>
  <template #repeatCountAppend>次</template><template #doubleRepeatCountAppend>次</template><template #doubleRepeatCountAppendSegment>至</template>
</NfTable></div>

<output aria-live="polite">{{ result }}</output>
</div>
</template>

<style scoped>
.table-examples {max-width:100%;min-width:0}
.table-fixed {height:420px;min-height:0}
.table-examples output {display:block;margin-top:16px;overflow-wrap:anywhere}
.table-examples :deep(.el-divider__text) {max-width:90%;white-space:normal;font-size:12px}
.table-examples :deep(.el-divider--horizontal) {margin:40px 0}
.table-examples :deep(.nf-search-form-control) {max-width:100%}
.table-examples :deep(.el-form--inline) {display:flex;flex-wrap:wrap;gap:0}
@media(max-width:600px){.table-examples :deep(.nf-search-form-item){max-width:100%;margin-right:0}.table-examples :deep(.el-form-item__content){min-width:0}}
</style>
```

## 各种slot定制+固定列 {#example-3}

### 各种slot定制+固定列
```vue
<script setup>
import { ref, reactive, h, onBeforeUnmount } from 'vue'
import { ElInput, ElDivider, ElCheckbox, ElPagination, ElTooltip, ElIcon, ElTableColumn, ElForm, ElFormItem } from 'element-plus'
import { QuestionFilled } from '@element-plus/icons-vue'
import { NfTable, NfSearchForm, NfButton, NfEmpty } from '@94ai-plus/common-ui'
const result = ref('')
const showStartTime = ref(false)
const report = (action, row) => result.value = action + (row ? ': ' + row.id : '')
const makeRows = (count, offset = 0) => Array.from({length:count}, (_, i) => ({
  id:offset+i+1, name:'任务'+(offset+i+1), taskId:i%3+1, companyName:'企业'+(i%3+1),
  operationName:'负责人'+(i+1), viceOperationName:'协作人'+(i+1), startTime:'2026-01-01',
  completionRate:i%2?0.6:1, unit:50+i%50, getOptionsId:i%3+1, address:'地址'+(i+1)
}))
const fields = [
  {prop:'normalInputBox',label:'普通输入框',element:'el-input',placeholder:'输入任务名称'},
  {prop:'numberInputBox',label:'数字输入框',element:'el-input-number',placeholder:'输入后搜索即清空数据'},
  {prop:'normalDropdown',label:'普通下拉',element:'el-select',options:[{label:'查询新增10条数据',value:1},{label:'查询数据结果为10条',value:2}]},
  {prop:'virtualDropdown',label:'虚拟下拉',element:'nf-virtual-select',options:[{label:'给点意见',value:'1'},{label:'售后问题',value:'2'}]},
  {prop:'opinion',label:'意见',element:'el-input',placeholder:'根据虚拟下拉显示或隐藏',destory:formData=>formData.virtualDropdown!=='1'},
  {prop:'slotInput',label:'nf-table插槽输入框',slot:'slotInput'},
]
const secondFields = [...fields.filter(field=>!['opinion','slotInput'].includes(field.prop)),
  {prop:'dynamicSlot',label:'从NfSearchForm自定义透传动态slot',slot:'dynamicNfSearchFormSlot'},
  {prop:'repeatCount',label:'测试number-range',element:'number-range',tag:'el-input',initValue:[],limitRange:[1,9999],inputSlot:{append:'repeatCountAppend',doubleAppend:'doubleRepeatCountAppend',doubleSegment:'doubleRepeatCountAppendSegment'}}]
const searchAttrs = {formOptions:fields,btnItems:['search'],columns:4,btnModel:'inline',columnEdit:true}
function useTable(key) {
  const table = ref(), rows = ref(makeRows(20)), allSelected = ref(false)
  const columns = ref([
    {type:'selection',prop:'selection',label:'选择',attr:{width:64,fixed:'left'}},
    {prop:'id',label:'id',labelTooltip:'配置tips',attr:{width:90}},
    {prop:'name',label:'任务名称',attr:{minWidth:160}},
    {prop:'companyName',label:()=>showStartTime.value?'所属企业(右边有日期)':'所属企业(右边无日期)',attr:{minWidth:190}},
    {prop:'startTime',label:'启动日期',destory:()=>!showStartTime.value,attr:{minWidth:150}},
    {prop:'unit',label:'unit数据单位',unit:'%',attr:{minWidth:135}},
    {prop:'taskId',label:'options映射名称',options:[{label:'任务1',value:1,tagType:'success'},{label:'任务2',value:2},{label:'任务3',value:3}],attr:{minWidth:150}},
    {prop:'getOptionsId',label:'getOptions映射名称',getOptions:done=>done([{label:'动态映射1',value:1},{label:'动态映射2',value:2,tagType:'tip'},{label:'动态映射3',value:3}]),attr:{minWidth:190}},
    {prop:'operation',label:'操作',attr:{fixed:'right',minWidth:210},operationSpan:3,operationList:scope=>[
      {name:'详情',onClick:row=>report('详情',row)},
      {name:'编辑',destroy:row=>row.completionRate===1,onClick:row=>report('编辑',row)},
      {name:'语音通知',onClick:row=>report('语音通知',row)},
      {name:'下载',destroy:true,onClick:row=>report('下载',row)},
    ]},
  ])
  const actions = reactive([
    {element:'el-checkbox',value:false,text:'当页全选',events:{change:()=>table.value?.toggleAllSelection()}},
    ...['开启','暂停','删除'].map((text,i)=>({element:'el-button',text,type:i?'danger':'primary',events:{click:()=>report(text)}})),
    {element:'el-button',get text(){return showStartTime.value?'隐藏启动日期':'显示启动日期'},get type(){return showStartTime.value?'danger':'primary'},events:{click:()=>showStartTime.value=!showStartTime.value}},
  ])
  const onSelection = selection => {
    const selected = selection.length > 0 && selection.length === table.value?.showData.length
    allSelected.value = selected; actions[0].value = selected
    result.value = '已选：'+selection.length
  }
  const search = ({data, callback}) => {
    try {
      if (data.numberInputBox) rows.value = []
      else if (data.normalDropdown === 1) rows.value = [...rows.value,...makeRows(10,rows.value.length)]
      else if (data.normalDropdown === 2) rows.value = makeRows(10)
      else rows.value = makeRows(20).filter(row=>row.name.includes(data.normalInputBox || ''))
      result.value = JSON.stringify(data)
    } finally { callback() }
  }
  return {table,rows,columns,actions,allSelected,onSelection,search,key}
}

const state = useTable('slots')
state.columns.value = [
 {type:'selection',prop:'selection',attr:{fixed:'left',width:64}},
 {prop:'id',label:'id',attr:{width:90}},
 {prop:'name',label:'任务名称',attr:{minWidth:180}},
 {prop:'startTime',label:'启动日期',labelTooltip:'任务启动时间',attr:{minWidth:170}},
 {prop:'operationName',label:'负责人',slot:'operationName',attr:{minWidth:220}},
 {prop:'completionRate',label:'完成率',headerSlot:'completionRateHeader',unit:'%',attr:{minWidth:160}},
 {prop:'operation',label:'操作',slot:'operation',attr:{fixed:'right',width:220}},
]
const currentPage = ref(1), pageSize = ref(5)
const showRows = () => state.rows.value.slice((currentPage.value-1)*pageSize.value,currentPage.value*pageSize.value)
function getSummaries({columns,data}) {return columns.map((column,index)=>index===0?'汇总':column.property==='completionRate'?data.reduce((sum,row)=>sum+row.completionRate,0):'')}

</script>

<template>
<div class="table-examples">
<NfTable :ref="value => state.table.value = value" :data="showRows()" :columns="state.columns.value" column-edit column-position="free"
 storage-key="docs-table-slots-zh" :table-attrs="{rowKey:'id',showSummary:true,summaryMethod:getSummaries}" @selection-change="state.onSelection">
 <template #columnEdit><NfButton type="primary" plain @click="state.table.value.nfColumCheckDialogVisible = true">slot定制表格列目显示隐藏</NfButton></template>
 <template #searchBox><NfSearchForm :form-options="fields" :btn-items="['search']" btn-model="inline" :columns="4" column-edit storage-key="docs-table-slot-search-zh"
   @on-search="data=>{state.search({data,callback:()=>{}});currentPage=1}" >
   <template #slotInput="{formData}"><ElInput v-model="formData.slotInput" /></template>
 </NfSearchForm></template>
 <template #operationName="{row}">{{ row.operationName }} {{ row.viceOperationName }}</template>
 <template #operation="{row}"><NfButton v-for="name in ['详情','编辑','语音']" :key="name" text @click="report(name,row)">{{ name }}</NfButton></template>
 <template #completionRateHeader><span>任务完成率</span><ElTooltip content="累计完成率=（累计导入数-进行中外呼数）/累计导入数"><ElIcon><QuestionFilled /></ElIcon></ElTooltip></template>
 <template #actionBar><ElCheckbox :model-value="state.allSelected.value" @change="state.table.value.toggleAllSelection()">当页全选</ElCheckbox>
  <NfButton v-for="name in ['开启','暂停','删除']" :key="name" @click="report(name)">{{ name }}</NfButton></template>
 <template #empty>定制empty</template><template #append>slot定制append</template>
 <template #pagination><ElPagination v-model:current-page="currentPage" v-model:page-size="pageSize" :page-sizes="[5,10,20]" :total="state.rows.value.length" layout="total,sizes,prev,pager,next" /></template>
</NfTable>
<ElDivider>上面当窗口很小时 操作列和选择列 固定横向拖拽</ElDivider><ElDivider>下面配合nf-empty使用</ElDivider>
<NfTable :data="[]" :columns="state.columns.value" :always-show-page="false" storage-key="docs-table-slot-empty-zh">
 <template #searchBox></template><template #append>slot定制append</template><template #empty><NfEmpty :image-size="145" /></template>
</NfTable>
<output aria-live="polite">{{ result }}</output>
</div>
</template>

<style scoped>
.table-examples {max-width:100%;min-width:0}
.table-fixed {height:420px;min-height:0}
.table-examples output {display:block;margin-top:16px;overflow-wrap:anywhere}
.table-examples :deep(.el-divider__text) {max-width:90%;white-space:normal;font-size:12px}
.table-examples :deep(.el-divider--horizontal) {margin:40px 0}
.table-examples :deep(.nf-search-form-control) {max-width:100%}
.table-examples :deep(.el-form--inline) {display:flex;flex-wrap:wrap;gap:0}
@media(max-width:600px){.table-examples :deep(.nf-search-form-item){max-width:100%;margin-right:0}.table-examples :deep(.el-form-item__content){min-width:0}}
</style>
```

## 数据加slot {#example-4}

### 数据加slot
```vue
<script setup>
import { ref, reactive, h, onBeforeUnmount } from 'vue'
import { ElInput, ElDivider, ElCheckbox, ElPagination, ElTooltip, ElIcon, ElTableColumn, ElForm, ElFormItem } from 'element-plus'
import { QuestionFilled } from '@element-plus/icons-vue'
import { NfTable, NfSearchForm, NfButton, NfEmpty } from '@94ai-plus/common-ui'
const result = ref('')
const showStartTime = ref(false)
const report = (action, row) => result.value = action + (row ? ': ' + row.id : '')
const makeRows = (count, offset = 0) => Array.from({length:count}, (_, i) => ({
  id:offset+i+1, name:'任务'+(offset+i+1), taskId:i%3+1, companyName:'企业'+(i%3+1),
  operationName:'负责人'+(i+1), viceOperationName:'协作人'+(i+1), startTime:'2026-01-01',
  completionRate:i%2?0.6:1, unit:50+i%50, getOptionsId:i%3+1, address:'地址'+(i+1)
}))
const fields = [
  {prop:'normalInputBox',label:'普通输入框',element:'el-input',placeholder:'输入任务名称'},
  {prop:'numberInputBox',label:'数字输入框',element:'el-input-number',placeholder:'输入后搜索即清空数据'},
  {prop:'normalDropdown',label:'普通下拉',element:'el-select',options:[{label:'查询新增10条数据',value:1},{label:'查询数据结果为10条',value:2}]},
  {prop:'virtualDropdown',label:'虚拟下拉',element:'nf-virtual-select',options:[{label:'给点意见',value:'1'},{label:'售后问题',value:'2'}]},
  {prop:'opinion',label:'意见',element:'el-input',placeholder:'根据虚拟下拉显示或隐藏',destory:formData=>formData.virtualDropdown!=='1'},
  {prop:'slotInput',label:'nf-table插槽输入框',slot:'slotInput'},
]
const secondFields = [...fields.filter(field=>!['opinion','slotInput'].includes(field.prop)),
  {prop:'dynamicSlot',label:'从NfSearchForm自定义透传动态slot',slot:'dynamicNfSearchFormSlot'},
  {prop:'repeatCount',label:'测试number-range',element:'number-range',tag:'el-input',initValue:[],limitRange:[1,9999],inputSlot:{append:'repeatCountAppend',doubleAppend:'doubleRepeatCountAppend',doubleSegment:'doubleRepeatCountAppendSegment'}}]
const searchAttrs = {formOptions:fields,btnItems:['search'],columns:4,btnModel:'inline',columnEdit:true}
function useTable(key) {
  const table = ref(), rows = ref(makeRows(20)), allSelected = ref(false)
  const columns = ref([
    {type:'selection',prop:'selection',label:'选择',attr:{width:64,fixed:'left'}},
    {prop:'id',label:'id',labelTooltip:'配置tips',attr:{width:90}},
    {prop:'name',label:'任务名称',attr:{minWidth:160}},
    {prop:'companyName',label:()=>showStartTime.value?'所属企业(右边有日期)':'所属企业(右边无日期)',attr:{minWidth:190}},
    {prop:'startTime',label:'启动日期',destory:()=>!showStartTime.value,attr:{minWidth:150}},
    {prop:'unit',label:'unit数据单位',unit:'%',attr:{minWidth:135}},
    {prop:'taskId',label:'options映射名称',options:[{label:'任务1',value:1,tagType:'success'},{label:'任务2',value:2},{label:'任务3',value:3}],attr:{minWidth:150}},
    {prop:'getOptionsId',label:'getOptions映射名称',getOptions:done=>done([{label:'动态映射1',value:1},{label:'动态映射2',value:2,tagType:'tip'},{label:'动态映射3',value:3}]),attr:{minWidth:190}},
    {prop:'operation',label:'操作',attr:{fixed:'right',minWidth:210},operationSpan:3,operationList:scope=>[
      {name:'详情',onClick:row=>report('详情',row)},
      {name:'编辑',destroy:row=>row.completionRate===1,onClick:row=>report('编辑',row)},
      {name:'语音通知',onClick:row=>report('语音通知',row)},
      {name:'下载',destroy:true,onClick:row=>report('下载',row)},
    ]},
  ])
  const actions = reactive([
    {element:'el-checkbox',value:false,text:'当页全选',events:{change:()=>table.value?.toggleAllSelection()}},
    ...['开启','暂停','删除'].map((text,i)=>({element:'el-button',text,type:i?'danger':'primary',events:{click:()=>report(text)}})),
    {element:'el-button',get text(){return showStartTime.value?'隐藏启动日期':'显示启动日期'},get type(){return showStartTime.value?'danger':'primary'},events:{click:()=>showStartTime.value=!showStartTime.value}},
  ])
  const onSelection = selection => {
    const selected = selection.length > 0 && selection.length === table.value?.showData.length
    allSelected.value = selected; actions[0].value = selected
    result.value = '已选：'+selection.length
  }
  const search = ({data, callback}) => {
    try {
      if (data.numberInputBox) rows.value = []
      else if (data.normalDropdown === 1) rows.value = [...rows.value,...makeRows(10,rows.value.length)]
      else if (data.normalDropdown === 2) rows.value = makeRows(10)
      else rows.value = makeRows(20).filter(row=>row.name.includes(data.normalInputBox || ''))
      result.value = JSON.stringify(data)
    } finally { callback() }
  }
  return {table,rows,columns,actions,allSelected,onSelection,search,key}
}

const state = useTable('data-slot')
const formFields = secondFields

</script>

<template>
<div class="table-examples">
<NfTable :ref="value=>state.table.value=value" :data="state.rows.value" :columns="state.columns.value" column-edit
 storage-key="docs-table-data-slot-zh" search-form-storage-key="docs-table-data-slot-search-zh" :search-form-attrs="{...searchAttrs,formOptions:formFields}"
 :action-bar-opt-list="state.actions" :page-attrs="{pageSize:5}" :table-attrs="{rowKey:'id'}" @selection-change="state.onSelection" @search-api="state.search">
 <template #dynamicNfSearchFormSlot="{formData}"><ElInput v-model="formData.dynamicSlot" clearable /></template>
 <template #repeatCountAppend>次</template><template #doubleRepeatCountAppend>次</template><template #doubleRepeatCountAppendSegment>至</template>
 <template #slotInput="{formData}"><ElInput v-model="formData.slotInput" clearable /></template>
</NfTable>
<output aria-live="polite">{{ result }}</output>
</div>
</template>

<style scoped>
.table-examples {max-width:100%;min-width:0}
.table-fixed {height:420px;min-height:0}
.table-examples output {display:block;margin-top:16px;overflow-wrap:anywhere}
.table-examples :deep(.el-divider__text) {max-width:90%;white-space:normal;font-size:12px}
.table-examples :deep(.el-divider--horizontal) {margin:40px 0}
.table-examples :deep(.nf-search-form-control) {max-width:100%}
.table-examples :deep(.el-form--inline) {display:flex;flex-wrap:wrap;gap:0}
@media(max-width:600px){.table-examples :deep(.nf-search-form-item){max-width:100%;margin-right:0}.table-examples :deep(.el-form-item__content){min-width:0}}
</style>
```

## 边框表格和表头嵌套 {#example-5}

### 边框表格和表头嵌套
```vue
<script setup>
import { ref, reactive, h, onBeforeUnmount } from 'vue'
import { ElInput, ElDivider, ElCheckbox, ElPagination, ElTooltip, ElIcon, ElTableColumn, ElForm, ElFormItem } from 'element-plus'
import { QuestionFilled } from '@element-plus/icons-vue'
import { NfTable, NfSearchForm, NfButton, NfEmpty } from '@94ai-plus/common-ui'
const result = ref('')
const showStartTime = ref(false)
const report = (action, row) => result.value = action + (row ? ': ' + row.id : '')
const makeRows = (count, offset = 0) => Array.from({length:count}, (_, i) => ({
  id:offset+i+1, name:'任务'+(offset+i+1), taskId:i%3+1, companyName:'企业'+(i%3+1),
  operationName:'负责人'+(i+1), viceOperationName:'协作人'+(i+1), startTime:'2026-01-01',
  completionRate:i%2?0.6:1, unit:50+i%50, getOptionsId:i%3+1, address:'地址'+(i+1)
}))
const fields = [
  {prop:'normalInputBox',label:'普通输入框',element:'el-input',placeholder:'输入任务名称'},
  {prop:'numberInputBox',label:'数字输入框',element:'el-input-number',placeholder:'输入后搜索即清空数据'},
  {prop:'normalDropdown',label:'普通下拉',element:'el-select',options:[{label:'查询新增10条数据',value:1},{label:'查询数据结果为10条',value:2}]},
  {prop:'virtualDropdown',label:'虚拟下拉',element:'nf-virtual-select',options:[{label:'给点意见',value:'1'},{label:'售后问题',value:'2'}]},
  {prop:'opinion',label:'意见',element:'el-input',placeholder:'根据虚拟下拉显示或隐藏',destory:formData=>formData.virtualDropdown!=='1'},
  {prop:'slotInput',label:'nf-table插槽输入框',slot:'slotInput'},
]
const secondFields = [...fields.filter(field=>!['opinion','slotInput'].includes(field.prop)),
  {prop:'dynamicSlot',label:'从NfSearchForm自定义透传动态slot',slot:'dynamicNfSearchFormSlot'},
  {prop:'repeatCount',label:'测试number-range',element:'number-range',tag:'el-input',initValue:[],limitRange:[1,9999],inputSlot:{append:'repeatCountAppend',doubleAppend:'doubleRepeatCountAppend',doubleSegment:'doubleRepeatCountAppendSegment'}}]
const searchAttrs = {formOptions:fields,btnItems:['search'],columns:4,btnModel:'inline',columnEdit:true}
function useTable(key) {
  const table = ref(), rows = ref(makeRows(20)), allSelected = ref(false)
  const columns = ref([
    {type:'selection',prop:'selection',label:'选择',attr:{width:64,fixed:'left'}},
    {prop:'id',label:'id',labelTooltip:'配置tips',attr:{width:90}},
    {prop:'name',label:'任务名称',attr:{minWidth:160}},
    {prop:'companyName',label:()=>showStartTime.value?'所属企业(右边有日期)':'所属企业(右边无日期)',attr:{minWidth:190}},
    {prop:'startTime',label:'启动日期',destory:()=>!showStartTime.value,attr:{minWidth:150}},
    {prop:'unit',label:'unit数据单位',unit:'%',attr:{minWidth:135}},
    {prop:'taskId',label:'options映射名称',options:[{label:'任务1',value:1,tagType:'success'},{label:'任务2',value:2},{label:'任务3',value:3}],attr:{minWidth:150}},
    {prop:'getOptionsId',label:'getOptions映射名称',getOptions:done=>done([{label:'动态映射1',value:1},{label:'动态映射2',value:2,tagType:'tip'},{label:'动态映射3',value:3}]),attr:{minWidth:190}},
    {prop:'operation',label:'操作',attr:{fixed:'right',minWidth:210},operationSpan:3,operationList:scope=>[
      {name:'详情',onClick:row=>report('详情',row)},
      {name:'编辑',destroy:row=>row.completionRate===1,onClick:row=>report('编辑',row)},
      {name:'语音通知',onClick:row=>report('语音通知',row)},
      {name:'下载',destroy:true,onClick:row=>report('下载',row)},
    ]},
  ])
  const actions = reactive([
    {element:'el-checkbox',value:false,text:'当页全选',events:{change:()=>table.value?.toggleAllSelection()}},
    ...['开启','暂停','删除'].map((text,i)=>({element:'el-button',text,type:i?'danger':'primary',events:{click:()=>report(text)}})),
    {element:'el-button',get text(){return showStartTime.value?'隐藏启动日期':'显示启动日期'},get type(){return showStartTime.value?'danger':'primary'},events:{click:()=>showStartTime.value=!showStartTime.value}},
  ])
  const onSelection = selection => {
    const selected = selection.length > 0 && selection.length === table.value?.showData.length
    allSelected.value = selected; actions[0].value = selected
    result.value = '已选：'+selection.length
  }
  const search = ({data, callback}) => {
    try {
      if (data.numberInputBox) rows.value = []
      else if (data.normalDropdown === 1) rows.value = [...rows.value,...makeRows(10,rows.value.length)]
      else if (data.normalDropdown === 2) rows.value = makeRows(10)
      else rows.value = makeRows(20).filter(row=>row.name.includes(data.normalInputBox || ''))
      result.value = JSON.stringify(data)
    } finally { callback() }
  }
  return {table,rows,columns,actions,allSelected,onSelection,search,key}
}

const state = useTable('nested')
state.columns.value.splice(2,0,{prop:'details',label:'嵌套表头',singleHeadMutiColSlot:'completionRateHeader'})

</script>

<template>
<div class="table-examples">
<NfTable :ref="value=>state.table.value=value" :data="state.rows.value" :columns="state.columns.value" column-edit storage-key="docs-table-nested-zh"
 search-form-storage-key="docs-table-nested-search-zh" :search-form-attrs="searchAttrs" :action-bar-opt-list="state.actions" :page-attrs="{pageSize:5}"
 :table-attrs="{rowKey:'id',border:true}" @selection-change="state.onSelection" @search-api="state.search">
 <template #completionRateHeader><ElTableColumn prop="name" label="嵌套字段1" min-width="160" /><ElTableColumn prop="address" label="嵌套字段2" min-width="160" /></template>
 <template #slotInput="{formData}"><ElInput v-model="formData.slotInput" /></template>
</NfTable>
<output aria-live="polite">{{ result }}</output>
</div>
</template>

<style scoped>
.table-examples {max-width:100%;min-width:0}
.table-fixed {height:420px;min-height:0}
.table-examples output {display:block;margin-top:16px;overflow-wrap:anywhere}
.table-examples :deep(.el-divider__text) {max-width:90%;white-space:normal;font-size:12px}
.table-examples :deep(.el-divider--horizontal) {margin:40px 0}
.table-examples :deep(.nf-search-form-control) {max-width:100%}
.table-examples :deep(.el-form--inline) {display:flex;flex-wrap:wrap;gap:0}
@media(max-width:600px){.table-examples :deep(.nf-search-form-item){max-width:100%;margin-right:0}.table-examples :deep(.el-form-item__content){min-width:0}}
</style>
```

## 表格排序+筛选 {#example-6}

### 表格排序+筛选
```vue
<script setup>
import { ref, reactive, h, onBeforeUnmount } from 'vue'
import { ElInput, ElDivider, ElCheckbox, ElPagination, ElTooltip, ElIcon, ElTableColumn, ElForm, ElFormItem } from 'element-plus'
import { QuestionFilled } from '@element-plus/icons-vue'
import { NfTable, NfSearchForm, NfButton, NfEmpty } from '@94ai-plus/common-ui'
const result = ref('')
const showStartTime = ref(false)
const report = (action, row) => result.value = action + (row ? ': ' + row.id : '')
const makeRows = (count, offset = 0) => Array.from({length:count}, (_, i) => ({
  id:offset+i+1, name:'任务'+(offset+i+1), taskId:i%3+1, companyName:'企业'+(i%3+1),
  operationName:'负责人'+(i+1), viceOperationName:'协作人'+(i+1), startTime:'2026-01-01',
  completionRate:i%2?0.6:1, unit:50+i%50, getOptionsId:i%3+1, address:'地址'+(i+1)
}))
const fields = [
  {prop:'normalInputBox',label:'普通输入框',element:'el-input',placeholder:'输入任务名称'},
  {prop:'numberInputBox',label:'数字输入框',element:'el-input-number',placeholder:'输入后搜索即清空数据'},
  {prop:'normalDropdown',label:'普通下拉',element:'el-select',options:[{label:'查询新增10条数据',value:1},{label:'查询数据结果为10条',value:2}]},
  {prop:'virtualDropdown',label:'虚拟下拉',element:'nf-virtual-select',options:[{label:'给点意见',value:'1'},{label:'售后问题',value:'2'}]},
  {prop:'opinion',label:'意见',element:'el-input',placeholder:'根据虚拟下拉显示或隐藏',destory:formData=>formData.virtualDropdown!=='1'},
  {prop:'slotInput',label:'nf-table插槽输入框',slot:'slotInput'},
]
const secondFields = [...fields.filter(field=>!['opinion','slotInput'].includes(field.prop)),
  {prop:'dynamicSlot',label:'从NfSearchForm自定义透传动态slot',slot:'dynamicNfSearchFormSlot'},
  {prop:'repeatCount',label:'测试number-range',element:'number-range',tag:'el-input',initValue:[],limitRange:[1,9999],inputSlot:{append:'repeatCountAppend',doubleAppend:'doubleRepeatCountAppend',doubleSegment:'doubleRepeatCountAppendSegment'}}]
const searchAttrs = {formOptions:fields,btnItems:['search'],columns:4,btnModel:'inline',columnEdit:true}
function useTable(key) {
  const table = ref(), rows = ref(makeRows(20)), allSelected = ref(false)
  const columns = ref([
    {type:'selection',prop:'selection',label:'选择',attr:{width:64,fixed:'left'}},
    {prop:'id',label:'id',labelTooltip:'配置tips',attr:{width:90}},
    {prop:'name',label:'任务名称',attr:{minWidth:160}},
    {prop:'companyName',label:()=>showStartTime.value?'所属企业(右边有日期)':'所属企业(右边无日期)',attr:{minWidth:190}},
    {prop:'startTime',label:'启动日期',destory:()=>!showStartTime.value,attr:{minWidth:150}},
    {prop:'unit',label:'unit数据单位',unit:'%',attr:{minWidth:135}},
    {prop:'taskId',label:'options映射名称',options:[{label:'任务1',value:1,tagType:'success'},{label:'任务2',value:2},{label:'任务3',value:3}],attr:{minWidth:150}},
    {prop:'getOptionsId',label:'getOptions映射名称',getOptions:done=>done([{label:'动态映射1',value:1},{label:'动态映射2',value:2,tagType:'tip'},{label:'动态映射3',value:3}]),attr:{minWidth:190}},
    {prop:'operation',label:'操作',attr:{fixed:'right',minWidth:210},operationSpan:3,operationList:scope=>[
      {name:'详情',onClick:row=>report('详情',row)},
      {name:'编辑',destroy:row=>row.completionRate===1,onClick:row=>report('编辑',row)},
      {name:'语音通知',onClick:row=>report('语音通知',row)},
      {name:'下载',destroy:true,onClick:row=>report('下载',row)},
    ]},
  ])
  const actions = reactive([
    {element:'el-checkbox',value:false,text:'当页全选',events:{change:()=>table.value?.toggleAllSelection()}},
    ...['开启','暂停','删除'].map((text,i)=>({element:'el-button',text,type:i?'danger':'primary',events:{click:()=>report(text)}})),
    {element:'el-button',get text(){return showStartTime.value?'隐藏启动日期':'显示启动日期'},get type(){return showStartTime.value?'danger':'primary'},events:{click:()=>showStartTime.value=!showStartTime.value}},
  ])
  const onSelection = selection => {
    const selected = selection.length > 0 && selection.length === table.value?.showData.length
    allSelected.value = selected; actions[0].value = selected
    result.value = '已选：'+selection.length
  }
  const search = ({data, callback}) => {
    try {
      if (data.numberInputBox) rows.value = []
      else if (data.normalDropdown === 1) rows.value = [...rows.value,...makeRows(10,rows.value.length)]
      else if (data.normalDropdown === 2) rows.value = makeRows(10)
      else rows.value = makeRows(20).filter(row=>row.name.includes(data.normalInputBox || ''))
      result.value = JSON.stringify(data)
    } finally { callback() }
  }
  return {table,rows,columns,actions,allSelected,onSelection,search,key}
}

const state = useTable('filter')
Object.assign(state.columns.value[1].attr,{sortable:true,columnKey:'id',filters:[{text:'>3',value:3},{text:'>10',value:10}],filterMultiple:false,filterMethod:(value,row)=>row.id>value})

</script>

<template>
<div class="table-examples">
<NfTable :ref="value=>state.table.value=value" :data="state.rows.value" :columns="state.columns.value" column-edit storage-key="docs-table-filter-zh"
 search-form-storage-key="docs-table-filter-search-zh" :search-form-attrs="searchAttrs" :action-bar-opt-list="state.actions" :page-attrs="{pageSize:20}"
 :table-attrs="{rowKey:'id',defaultSort:{prop:'id',order:'descending'}}" @selection-change="state.onSelection" @search-api="state.search"
 @sort-change="value=>result=JSON.stringify({sort:value.prop,order:value.order})" @filter-change="value=>result=JSON.stringify(value)">
 <template #slotInput="{formData}"><ElInput v-model="formData.slotInput" /></template>
</NfTable>
<output aria-live="polite">{{ result }}</output>
</div>
</template>

<style scoped>
.table-examples {max-width:100%;min-width:0}
.table-fixed {height:420px;min-height:0}
.table-examples output {display:block;margin-top:16px;overflow-wrap:anywhere}
.table-examples :deep(.el-divider__text) {max-width:90%;white-space:normal;font-size:12px}
.table-examples :deep(.el-divider--horizontal) {margin:40px 0}
.table-examples :deep(.nf-search-form-control) {max-width:100%}
.table-examples :deep(.el-form--inline) {display:flex;flex-wrap:wrap;gap:0}
@media(max-width:600px){.table-examples :deep(.nf-search-form-item){max-width:100%;margin-right:0}.table-examples :deep(.el-form-item__content){min-width:0}}
</style>
```

<span id="tree"></span>

## 展开行和树形数据 {#example-7}

### 展开行和树形数据
```vue
<script setup>
import { ref, reactive, h, onBeforeUnmount } from 'vue'
import { ElInput, ElDivider, ElCheckbox, ElPagination, ElTooltip, ElIcon, ElTableColumn, ElForm, ElFormItem } from 'element-plus'
import { QuestionFilled } from '@element-plus/icons-vue'
import { NfTable, NfSearchForm, NfButton, NfEmpty } from '@94ai-plus/common-ui'
const result = ref('')
const showStartTime = ref(false)
const report = (action, row) => result.value = action + (row ? ': ' + row.id : '')
const makeRows = (count, offset = 0) => Array.from({length:count}, (_, i) => ({
  id:offset+i+1, name:'任务'+(offset+i+1), taskId:i%3+1, companyName:'企业'+(i%3+1),
  operationName:'负责人'+(i+1), viceOperationName:'协作人'+(i+1), startTime:'2026-01-01',
  completionRate:i%2?0.6:1, unit:50+i%50, getOptionsId:i%3+1, address:'地址'+(i+1)
}))
const fields = [
  {prop:'normalInputBox',label:'普通输入框',element:'el-input',placeholder:'输入任务名称'},
  {prop:'numberInputBox',label:'数字输入框',element:'el-input-number',placeholder:'输入后搜索即清空数据'},
  {prop:'normalDropdown',label:'普通下拉',element:'el-select',options:[{label:'查询新增10条数据',value:1},{label:'查询数据结果为10条',value:2}]},
  {prop:'virtualDropdown',label:'虚拟下拉',element:'nf-virtual-select',options:[{label:'给点意见',value:'1'},{label:'售后问题',value:'2'}]},
  {prop:'opinion',label:'意见',element:'el-input',placeholder:'根据虚拟下拉显示或隐藏',destory:formData=>formData.virtualDropdown!=='1'},
  {prop:'slotInput',label:'nf-table插槽输入框',slot:'slotInput'},
]
const secondFields = [...fields.filter(field=>!['opinion','slotInput'].includes(field.prop)),
  {prop:'dynamicSlot',label:'从NfSearchForm自定义透传动态slot',slot:'dynamicNfSearchFormSlot'},
  {prop:'repeatCount',label:'测试number-range',element:'number-range',tag:'el-input',initValue:[],limitRange:[1,9999],inputSlot:{append:'repeatCountAppend',doubleAppend:'doubleRepeatCountAppend',doubleSegment:'doubleRepeatCountAppendSegment'}}]
const searchAttrs = {formOptions:fields,btnItems:['search'],columns:4,btnModel:'inline',columnEdit:true}
function useTable(key) {
  const table = ref(), rows = ref(makeRows(20)), allSelected = ref(false)
  const columns = ref([
    {type:'selection',prop:'selection',label:'选择',attr:{width:64,fixed:'left'}},
    {prop:'id',label:'id',labelTooltip:'配置tips',attr:{width:90}},
    {prop:'name',label:'任务名称',attr:{minWidth:160}},
    {prop:'companyName',label:()=>showStartTime.value?'所属企业(右边有日期)':'所属企业(右边无日期)',attr:{minWidth:190}},
    {prop:'startTime',label:'启动日期',destory:()=>!showStartTime.value,attr:{minWidth:150}},
    {prop:'unit',label:'unit数据单位',unit:'%',attr:{minWidth:135}},
    {prop:'taskId',label:'options映射名称',options:[{label:'任务1',value:1,tagType:'success'},{label:'任务2',value:2},{label:'任务3',value:3}],attr:{minWidth:150}},
    {prop:'getOptionsId',label:'getOptions映射名称',getOptions:done=>done([{label:'动态映射1',value:1},{label:'动态映射2',value:2,tagType:'tip'},{label:'动态映射3',value:3}]),attr:{minWidth:190}},
    {prop:'operation',label:'操作',attr:{fixed:'right',minWidth:210},operationSpan:3,operationList:scope=>[
      {name:'详情',onClick:row=>report('详情',row)},
      {name:'编辑',destroy:row=>row.completionRate===1,onClick:row=>report('编辑',row)},
      {name:'语音通知',onClick:row=>report('语音通知',row)},
      {name:'下载',destroy:true,onClick:row=>report('下载',row)},
    ]},
  ])
  const actions = reactive([
    {element:'el-checkbox',value:false,text:'当页全选',events:{change:()=>table.value?.toggleAllSelection()}},
    ...['开启','暂停','删除'].map((text,i)=>({element:'el-button',text,type:i?'danger':'primary',events:{click:()=>report(text)}})),
    {element:'el-button',get text(){return showStartTime.value?'隐藏启动日期':'显示启动日期'},get type(){return showStartTime.value?'danger':'primary'},events:{click:()=>showStartTime.value=!showStartTime.value}},
  ])
  const onSelection = selection => {
    const selected = selection.length > 0 && selection.length === table.value?.showData.length
    allSelected.value = selected; actions[0].value = selected
    result.value = '已选：'+selection.length
  }
  const search = ({data, callback}) => {
    try {
      if (data.numberInputBox) rows.value = []
      else if (data.normalDropdown === 1) rows.value = [...rows.value,...makeRows(10,rows.value.length)]
      else if (data.normalDropdown === 2) rows.value = makeRows(10)
      else rows.value = makeRows(20).filter(row=>row.name.includes(data.normalInputBox || ''))
      result.value = JSON.stringify(data)
    } finally { callback() }
  }
  return {table,rows,columns,actions,allSelected,onSelection,search,key}
}

const expanded = useTable('expand'), tree = useTable('tree')
expanded.columns.value.unshift({type:'expand',prop:'expand',slot:'expandSlot'})
tree.columns.value.splice(1,0,{prop:'name',label:'任务名称',attr:{minWidth:200}})
tree.rows.value = makeRows(5).map((row,i)=>({...row,children:makeRows(2,100+i*2)}))

</script>

<template>
<div class="table-examples">
<NfTable :ref="value=>expanded.table.value=value" :data="expanded.rows.value" :columns="expanded.columns.value" column-edit storage-key="docs-table-expand-zh"
 search-form-storage-key="docs-table-expand-search-zh" :search-form-attrs="searchAttrs" :page-attrs="{pageSize:5}" :table-attrs="{rowKey:'id'}" @search-api="expanded.search">
 <template #slotInput="{formData}"><ElInput v-model="formData.slotInput" /></template>
 <template #expandSlot="{row}"><ElForm label-position="left" label-width="100px">
  <ElFormItem v-for="field in [{prop:'id',label:'id'},{prop:'taskId',label:'编号'},{prop:'name',label:'任务名称'},{prop:'companyName',label:'所属企业'},{prop:'startTime',label:'启动日期'},{prop:'completionRate',label:'完成率'},{prop:'operationName',label:'负责人'}]" :key="field.prop" :label="field.label">{{ row[field.prop] }}</ElFormItem>
  <ElFormItem label="还有更多内容">xxxx</ElFormItem>
 </ElForm></template>
</NfTable><ElDivider>上面展开行</ElDivider><ElDivider>下面树形表格</ElDivider>
<NfTable :ref="value=>tree.table.value=value" :data="tree.rows.value" :columns="tree.columns.value" column-edit storage-key="docs-table-tree-zh"
 search-form-storage-key="docs-table-tree-search-zh" :search-form-attrs="searchAttrs" :table-attrs="{rowKey:'id',treeProps:{children:'children'}}" :page-attrs="{pageSize:5}" :action-bar-opt-list="tree.actions" @selection-change="tree.onSelection">
 <template #slotInput="{formData}"><ElInput v-model="formData.slotInput" /></template>
</NfTable>
<output aria-live="polite">{{ result }}</output>
</div>
</template>

<style scoped>
.table-examples {max-width:100%;min-width:0}
.table-fixed {height:420px;min-height:0}
.table-examples output {display:block;margin-top:16px;overflow-wrap:anywhere}
.table-examples :deep(.el-divider__text) {max-width:90%;white-space:normal;font-size:12px}
.table-examples :deep(.el-divider--horizontal) {margin:40px 0}
.table-examples :deep(.nf-search-form-control) {max-width:100%}
.table-examples :deep(.el-form--inline) {display:flex;flex-wrap:wrap;gap:0}
@media(max-width:600px){.table-examples :deep(.nf-search-form-item){max-width:100%;margin-right:0}.table-examples :deep(.el-form-item__content){min-width:0}}
</style>
```

<span id="virtual"></span>

## 无分页的虚拟表格 {#example-8}

### 无分页的虚拟表格
```vue
<script setup>
import { ref, reactive, h, onBeforeUnmount } from 'vue'
import { ElInput, ElDivider, ElCheckbox, ElPagination, ElTooltip, ElIcon, ElTableColumn, ElForm, ElFormItem } from 'element-plus'
import { QuestionFilled } from '@element-plus/icons-vue'
import { NfTable, NfSearchForm, NfButton, NfEmpty } from '@94ai-plus/common-ui'
const result = ref('')
const showStartTime = ref(false)
const report = (action, row) => result.value = action + (row ? ': ' + row.id : '')
const makeRows = (count, offset = 0) => Array.from({length:count}, (_, i) => ({
  id:offset+i+1, name:'任务'+(offset+i+1), taskId:i%3+1, companyName:'企业'+(i%3+1),
  operationName:'负责人'+(i+1), viceOperationName:'协作人'+(i+1), startTime:'2026-01-01',
  completionRate:i%2?0.6:1, unit:50+i%50, getOptionsId:i%3+1, address:'地址'+(i+1)
}))
const fields = [
  {prop:'normalInputBox',label:'普通输入框',element:'el-input',placeholder:'输入任务名称'},
  {prop:'numberInputBox',label:'数字输入框',element:'el-input-number',placeholder:'输入后搜索即清空数据'},
  {prop:'normalDropdown',label:'普通下拉',element:'el-select',options:[{label:'查询新增10条数据',value:1},{label:'查询数据结果为10条',value:2}]},
  {prop:'virtualDropdown',label:'虚拟下拉',element:'nf-virtual-select',options:[{label:'给点意见',value:'1'},{label:'售后问题',value:'2'}]},
  {prop:'opinion',label:'意见',element:'el-input',placeholder:'根据虚拟下拉显示或隐藏',destory:formData=>formData.virtualDropdown!=='1'},
  {prop:'slotInput',label:'nf-table插槽输入框',slot:'slotInput'},
]
const secondFields = [...fields.filter(field=>!['opinion','slotInput'].includes(field.prop)),
  {prop:'dynamicSlot',label:'从NfSearchForm自定义透传动态slot',slot:'dynamicNfSearchFormSlot'},
  {prop:'repeatCount',label:'测试number-range',element:'number-range',tag:'el-input',initValue:[],limitRange:[1,9999],inputSlot:{append:'repeatCountAppend',doubleAppend:'doubleRepeatCountAppend',doubleSegment:'doubleRepeatCountAppendSegment'}}]
const searchAttrs = {formOptions:fields,btnItems:['search'],columns:4,btnModel:'inline',columnEdit:true}
function useTable(key) {
  const table = ref(), rows = ref(makeRows(20)), allSelected = ref(false)
  const columns = ref([
    {type:'selection',prop:'selection',label:'选择',attr:{width:64,fixed:'left'}},
    {prop:'id',label:'id',labelTooltip:'配置tips',attr:{width:90}},
    {prop:'name',label:'任务名称',attr:{minWidth:160}},
    {prop:'companyName',label:()=>showStartTime.value?'所属企业(右边有日期)':'所属企业(右边无日期)',attr:{minWidth:190}},
    {prop:'startTime',label:'启动日期',destory:()=>!showStartTime.value,attr:{minWidth:150}},
    {prop:'unit',label:'unit数据单位',unit:'%',attr:{minWidth:135}},
    {prop:'taskId',label:'options映射名称',options:[{label:'任务1',value:1,tagType:'success'},{label:'任务2',value:2},{label:'任务3',value:3}],attr:{minWidth:150}},
    {prop:'getOptionsId',label:'getOptions映射名称',getOptions:done=>done([{label:'动态映射1',value:1},{label:'动态映射2',value:2,tagType:'tip'},{label:'动态映射3',value:3}]),attr:{minWidth:190}},
    {prop:'operation',label:'操作',attr:{fixed:'right',minWidth:210},operationSpan:3,operationList:scope=>[
      {name:'详情',onClick:row=>report('详情',row)},
      {name:'编辑',destroy:row=>row.completionRate===1,onClick:row=>report('编辑',row)},
      {name:'语音通知',onClick:row=>report('语音通知',row)},
      {name:'下载',destroy:true,onClick:row=>report('下载',row)},
    ]},
  ])
  const actions = reactive([
    {element:'el-checkbox',value:false,text:'当页全选',events:{change:()=>table.value?.toggleAllSelection()}},
    ...['开启','暂停','删除'].map((text,i)=>({element:'el-button',text,type:i?'danger':'primary',events:{click:()=>report(text)}})),
    {element:'el-button',get text(){return showStartTime.value?'隐藏启动日期':'显示启动日期'},get type(){return showStartTime.value?'danger':'primary'},events:{click:()=>showStartTime.value=!showStartTime.value}},
  ])
  const onSelection = selection => {
    const selected = selection.length > 0 && selection.length === table.value?.showData.length
    allSelected.value = selected; actions[0].value = selected
    result.value = '已选：'+selection.length
  }
  const search = ({data, callback}) => {
    try {
      if (data.numberInputBox) rows.value = []
      else if (data.normalDropdown === 1) rows.value = [...rows.value,...makeRows(10,rows.value.length)]
      else if (data.normalDropdown === 2) rows.value = makeRows(10)
      else rows.value = makeRows(20).filter(row=>row.name.includes(data.normalInputBox || ''))
      result.value = JSON.stringify(data)
    } finally { callback() }
  }
  return {table,rows,columns,actions,allSelected,onSelection,search,key}
}

const table = ref(), selected = ref(0), all = ref(false)
const makeData = count => makeRows(count).map(row=>({...row,age:18+row.id%48,email:'user'+row.id+'@example.com',registerDate:'2026-01-01'}))
const rows = ref(makeData(1500))
const columns = [{type:'selection',prop:'selection',attr:{width:60}},...['id','name','age','email','address','registerDate'].map((prop,i)=>({prop,label:['id','姓名','年龄','邮件','地址','时间'][i],attr:{minWidth:120}})),{prop:'operation',label:'操作',slot:'operation',attr:{fixed:'right',width:140}}]

</script>

<template>
<div class="table-examples">
<NfTable ref="table" :data="rows" :columns="columns" column-edit storage-key="docs-table-virtual-zh" :virtualized="rows.length>100" :virtual-table-data="rows" :always-show-page="false"
 :virtual-props="{rowHeight:70,height:500}" :table-attrs="{rowKey:'id',maxHeight:500}" @selection-change="value=>{selected=value.length;all=value.length===rows.length}">
 <template #actionBar><ElCheckbox :model-value="all" @change="value=>value?table.toggleAllSelection():table.clearSelection()">全部</ElCheckbox><span>已选：{{ selected }}</span></template>
 <template #operation="{row,index}"><NfButton text size="mini" @click="result=JSON.stringify({row,index})">打印行信息</NfButton></template>
</NfTable><div style="display:flex;gap:12px;margin-top:16px"><NfButton @click="rows=makeData(50);table.clearSelection()">50条</NfButton><NfButton @click="rows=makeData(1500);table.clearSelection()">1500条</NfButton></div>
<output aria-live="polite">{{ result }}</output>
</div>
</template>

<style scoped>
.table-examples {max-width:100%;min-width:0}
.table-fixed {height:420px;min-height:0}
.table-examples output {display:block;margin-top:16px;overflow-wrap:anywhere}
.table-examples :deep(.el-divider__text) {max-width:90%;white-space:normal;font-size:12px}
.table-examples :deep(.el-divider--horizontal) {margin:40px 0}
.table-examples :deep(.nf-search-form-control) {max-width:100%}
.table-examples :deep(.el-form--inline) {display:flex;flex-wrap:wrap;gap:0}
@media(max-width:600px){.table-examples :deep(.nf-search-form-item){max-width:100%;margin-right:0}.table-examples :deep(.el-form-item__content){min-width:0}}
</style>
```

## 固定右侧操作列拖拽与指示线边界 {#example-9}

### 固定右侧操作列拖拽与指示线边界
```vue
<script setup>
import { ref, reactive, h, onBeforeUnmount } from 'vue'
import { ElInput, ElDivider, ElCheckbox, ElPagination, ElTooltip, ElIcon, ElTableColumn, ElForm, ElFormItem } from 'element-plus'
import { QuestionFilled } from '@element-plus/icons-vue'
import { NfTable, NfSearchForm, NfButton, NfEmpty } from '@94ai-plus/common-ui'
const result = ref('')
const showStartTime = ref(false)
const report = (action, row) => result.value = action + (row ? ': ' + row.id : '')
const makeRows = (count, offset = 0) => Array.from({length:count}, (_, i) => ({
  id:offset+i+1, name:'任务'+(offset+i+1), taskId:i%3+1, companyName:'企业'+(i%3+1),
  operationName:'负责人'+(i+1), viceOperationName:'协作人'+(i+1), startTime:'2026-01-01',
  completionRate:i%2?0.6:1, unit:50+i%50, getOptionsId:i%3+1, address:'地址'+(i+1)
}))
const fields = [
  {prop:'normalInputBox',label:'普通输入框',element:'el-input',placeholder:'输入任务名称'},
  {prop:'numberInputBox',label:'数字输入框',element:'el-input-number',placeholder:'输入后搜索即清空数据'},
  {prop:'normalDropdown',label:'普通下拉',element:'el-select',options:[{label:'查询新增10条数据',value:1},{label:'查询数据结果为10条',value:2}]},
  {prop:'virtualDropdown',label:'虚拟下拉',element:'nf-virtual-select',options:[{label:'给点意见',value:'1'},{label:'售后问题',value:'2'}]},
  {prop:'opinion',label:'意见',element:'el-input',placeholder:'根据虚拟下拉显示或隐藏',destory:formData=>formData.virtualDropdown!=='1'},
  {prop:'slotInput',label:'nf-table插槽输入框',slot:'slotInput'},
]
const secondFields = [...fields.filter(field=>!['opinion','slotInput'].includes(field.prop)),
  {prop:'dynamicSlot',label:'从NfSearchForm自定义透传动态slot',slot:'dynamicNfSearchFormSlot'},
  {prop:'repeatCount',label:'测试number-range',element:'number-range',tag:'el-input',initValue:[],limitRange:[1,9999],inputSlot:{append:'repeatCountAppend',doubleAppend:'doubleRepeatCountAppend',doubleSegment:'doubleRepeatCountAppendSegment'}}]
const searchAttrs = {formOptions:fields,btnItems:['search'],columns:4,btnModel:'inline',columnEdit:true}
function useTable(key) {
  const table = ref(), rows = ref(makeRows(20)), allSelected = ref(false)
  const columns = ref([
    {type:'selection',prop:'selection',label:'选择',attr:{width:64,fixed:'left'}},
    {prop:'id',label:'id',labelTooltip:'配置tips',attr:{width:90}},
    {prop:'name',label:'任务名称',attr:{minWidth:160}},
    {prop:'companyName',label:()=>showStartTime.value?'所属企业(右边有日期)':'所属企业(右边无日期)',attr:{minWidth:190}},
    {prop:'startTime',label:'启动日期',destory:()=>!showStartTime.value,attr:{minWidth:150}},
    {prop:'unit',label:'unit数据单位',unit:'%',attr:{minWidth:135}},
    {prop:'taskId',label:'options映射名称',options:[{label:'任务1',value:1,tagType:'success'},{label:'任务2',value:2},{label:'任务3',value:3}],attr:{minWidth:150}},
    {prop:'getOptionsId',label:'getOptions映射名称',getOptions:done=>done([{label:'动态映射1',value:1},{label:'动态映射2',value:2,tagType:'tip'},{label:'动态映射3',value:3}]),attr:{minWidth:190}},
    {prop:'operation',label:'操作',attr:{fixed:'right',minWidth:210},operationSpan:3,operationList:scope=>[
      {name:'详情',onClick:row=>report('详情',row)},
      {name:'编辑',destroy:row=>row.completionRate===1,onClick:row=>report('编辑',row)},
      {name:'语音通知',onClick:row=>report('语音通知',row)},
      {name:'下载',destroy:true,onClick:row=>report('下载',row)},
    ]},
  ])
  const actions = reactive([
    {element:'el-checkbox',value:false,text:'当页全选',events:{change:()=>table.value?.toggleAllSelection()}},
    ...['开启','暂停','删除'].map((text,i)=>({element:'el-button',text,type:i?'danger':'primary',events:{click:()=>report(text)}})),
    {element:'el-button',get text(){return showStartTime.value?'隐藏启动日期':'显示启动日期'},get type(){return showStartTime.value?'danger':'primary'},events:{click:()=>showStartTime.value=!showStartTime.value}},
  ])
  const onSelection = selection => {
    const selected = selection.length > 0 && selection.length === table.value?.showData.length
    allSelected.value = selected; actions[0].value = selected
    result.value = '已选：'+selection.length
  }
  const search = ({data, callback}) => {
    try {
      if (data.numberInputBox) rows.value = []
      else if (data.normalDropdown === 1) rows.value = [...rows.value,...makeRows(10,rows.value.length)]
      else if (data.normalDropdown === 2) rows.value = makeRows(10)
      else rows.value = makeRows(20).filter(row=>row.name.includes(data.normalInputBox || ''))
      result.value = JSON.stringify(data)
    } finally { callback() }
  }
  return {table,rows,columns,actions,allSelected,onSelection,search,key}
}

const rows = [{id:1,name:'Alice',status:1},{id:2,name:'Bob',status:0}]
const columns = ref([{prop:'id',label:'ID',attr:{width:100}},{prop:'name',label:'姓名',attr:{minWidth:120}},{prop:'operation',label:'操作',operationSpan:0,attr:{fixed:'right',width:160},operationList:[{name:'编辑',key:'edit',onClick:row=>report('编辑',row)},{name:'删除',key:'del',type:'danger',onClick:row=>report('删除',row)}]}])
function onFixedDragEnd({width,oldWidth,prop}) {columns.value[2].attr.width=width;result.value=JSON.stringify({width,oldWidth,prop})}

</script>

<template>
<div class="table-examples">
<div style="height:480px"><NfTable :data="rows" :columns="columns" cal-height column-edit storage-key="docs-table-fixed-drag-zh"
 fixed-right-drag-enabled :drag-indicator-padding-left="170" :drag-indicator-padding-right="170" @fixed-column-drag-end="onFixedDragEnd" /></div>
<output aria-live="polite">{{ result }}</output>
</div>
</template>

<style scoped>
.table-examples {max-width:100%;min-width:0}
.table-fixed {height:420px;min-height:0}
.table-examples output {display:block;margin-top:16px;overflow-wrap:anywhere}
.table-examples :deep(.el-divider__text) {max-width:90%;white-space:normal;font-size:12px}
.table-examples :deep(.el-divider--horizontal) {margin:40px 0}
.table-examples :deep(.nf-search-form-control) {max-width:100%}
.table-examples :deep(.el-form--inline) {display:flex;flex-wrap:wrap;gap:0}
@media(max-width:600px){.table-examples :deep(.nf-search-form-item){max-width:100%;margin-right:0}.table-examples :deep(.el-form-item__content){min-width:0}}
</style>
```

## NfTableColumnAttributes {#column-options}

| 参数 | 说明 | 类型 |
| --- | --- | --- |
| key | 列的唯一标识；未设置 prop 时用作回退标识。 | string / number |
| prop | 列字段路径。 | string |
| type | 选择列、序号列或展开列。 | selection / index / expand |
| label | 列标题，也可由函数返回。 | string / Function |
| attr | Element Plus TableColumn 公开属性。 | ElTableColumnAttributes |
| slot | 单元格具名插槽。 | string |
| headerSlot | 表头具名插槽。 | string |
| singleHeadMutiColSlot | 单个表头下嵌套 TableColumn 插槽。 | string |
| children | 嵌套表头列定义。 | NfTableColumnAttributes[] |
| render | 使用 Vue 3 h 或 VNode 定制单元格。 | (row, scope) =&gt; VNodeChild |
| labelTooltip / labelTooltipPlacement | 表头提示及位置。 | string |
| unit | 数据单位后缀。 | string |
| options / getOptions | 静态或异步枚举映射；选项支持 tagType。 | array / Function |
| optionsEnum / optionsTag | 值到文本、标签类型的映射。 | object |
| operationList | 操作按钮配置或按行返回配置的函数。 | array / Function |
| operationSpan | 操作按钮超过指定数量时折叠；0 按宽度。 | number |
| initHidden | 列初始隐藏状态。 | boolean |
| destroy / destory / show | 按配置控制列显示。 | boolean / Function |
| fit.tags | 参与内容宽度估算的标签。 | string[] |

## Attribute {#props}

| 参数 | 说明 | 类型 | 可选值 | 默认值 |
| --- | --- | --- | --- | --- |
| data | 填充表格数据 | Record&lt;string, any&gt;[] | — | [] |
| columns | 渲染表头json data | NfTableColumnAttributes[] | — | [] |
| searchFormAttrs | 表单属性,跟nf-search-form Attributes属性一样 | NfSearchFormAttributes | — | {} |
| pageAttrs | 分页属性。省略 total 使用前端分页；传入 total 使用服务端分页，业务方按请求返回当前页数据。 | ElPaginationAttributes | — | {} |
| tableAttrs | 表格属性，透传 Element Plus Table 的公开属性。 | ElTableAttributes | — | {} |
| searchFormEvents | 表单事件 跟nf-search-form组件Events一致 | Partial&lt;Record&lt;NfSearchFormEventKey, Function&gt;&gt; | — | {} |
| pageEvents | 分页事件 跟el-pagination组件Events一致 | Partial&lt;Record&lt;ElPaginationEventKey, Function&gt;&gt; | — | {} |
| tableEvents | 表格事件 跟el-table组件Table Events一致 | Partial&lt;Record&lt;ElTableEventKey, Function&gt;&gt; | — | {} |
| actionBarOptList | actionBar按钮渲染json data | NfTableActionBtnAttributes[] | — | [] |
| operationPropKey | 数据驱动渲染单元格操作按钮,指定单元格的prop值定义为按钮操作列的key | string | — | 'operation' |
| alwaysShowPage | 是否始终显示分页；虚拟表格不显示分页。 | boolean | — | true |
| calHeight | 固定窗口满屏(或满父容器)table自动计算高度,用来实现一个窗口table固定高度内容滚动(content限高自滚动),这是相对较好的表格交互效果 | boolean | — | false |
| dragCached | 是否缓存列拖拽宽度，使用 IndexedDB。 | boolean | — | true |
| dragIndicatorPaddingLeft | 固定右侧列拖拽指示线距离左侧的最小距离（px） | number | — | 120 |
| dragIndicatorPaddingRight | 固定右侧列拖拽指示线距离右侧的最小距离（px） | number | — | 120 |
| fixedRightDragEnabled | 是否开启固定在右侧操作列的自定义拖拽句柄 | boolean | — | false |
| emptyImageSize | 表格空数据时空组件size | number | — | 145 |
| initSearchApi | 初始化是否自动查询；未传时跟随 setEasyConf。 | boolean | 不传则跟随setEasyConf | undefined |
| pageChangeSearchApi | 分页变化是否自动查询；未传时跟随 setEasyConf。 | boolean | 不传则跟随setEasyConf | undefined |
| pageKeys | 分页使用的字段 | string[] | - | ['pageNo', 'pageSize'] |
| setEasyConf | 启用简易配置，提供初始化查询、分页查询、搜索布局及 row-key 默认值，显式设置优先。 | boolean | 请查阅 | false |
| loading功能 |  |  |  |  |
| loading | 表格loading | boolean | — | false |
| target | Loading 需要覆盖的 DOM 节点。可传入一个 DOM 对象或字符串；若传入字符串，则会将其作为参数传入 document.querySelector以获取到对应 DOM 节点 | HTMLElement | — | undefined |
| body | 同 v-loading 指令中的 body 修饰符 | boolean | — | false |
| fullscreen | 同 v-loading 指令中的 fullscreen 修饰符 | boolean | — | false |
| lock | 同 v-loading 指令中的 lock 修饰符 | boolean | — | false |
| text | Loading 显示在加载图标下方的加载文案 | string | — | undefined |
| spinner | Loading 自定义加载图标类名 | string | — | undefined |
| background | Loading 遮罩背景色 | string | — | undefined |
| customClass | Loading 的自定义类名 | string | — | undefined |
| columnEdit | 列编辑功能开关。 | boolean | — | false |
| columnPosition | 列编辑按钮位置 | string | free/embed | 'embed' |
| showColumn | 列编辑初始化要显示的表格项字段prop集合，[]代表显示所有，可以和columns的initHidden配合使用 | string[] | — | undefined |
| priority | 列编辑缓存回显优先级，处理item.initHidden,form.showColumn和IndexedDB.cache的回显关系 | string | cached/value | 'cached' |
| storageKey | 表格列设置的 IndexedDB 缓存键；同页多实例应使用独立键。 | string | - | `nf-table-columns-cached-key-${routeName}` |
| searchFormStorageKey | 可选，含义同storageKey,nfSearchForm设置字段缓存key,也可以在searchFormAttrs设置storageKey | string | - | `nf-search-form-columns-cached-key-${routeName}` |
| checkMode | 可选，列编辑交互模式，默认drawer（drawer/dialog） | string | dialog/drawer | 'drawer' |
| columnDisplayBtnClass | 列编辑按钮类名 | string | — | '' |
| columnDisplayBtnIcon | 列编辑按钮图标 | string | — | undefined |
| columnDisplayBtnType | 列编辑按钮类型 | string | — | 'primary' |
| columnDisplayBtnPlain | 列编辑按钮镂空 | boolean | — | true |
| columnDisplayBtnSize | 列编辑按钮尺寸 | string | — | 'mini' |
| columnDisplayBtnRound | 列编辑按钮圆角 | boolean | — | false |
| columnDisplayBtnCircle | 列编辑按钮圆形 | boolean | — | false |
| columnDisplayBtnLoading | 列编辑按钮Loading | boolean | — | false |
| columnDisplayBtnDisabled | 列编辑按钮禁用 | boolean | — | false |
| columnDisplayBtnText | 列编辑按钮文本 | string | — | 跟随语言包 |
| columnCheckTitle | 列编辑dialog/drawer模式-&gt;弹框标题 | string | - | 设置显示字段 |
| columnCheckCancelButtonText | 列编辑dialog/drawer模式取消按钮文本 | string | - | '取消' |
| columnCheckConfirmButtonText | 列编辑dialog/drawer模式确定按钮文本 | string | - | '确定' |
| columnCheckBasicFieldDesc | 默认category分类标题 | string | - | 跟随语言包 |
| columnCheckWidth | 列编辑dialog模式-&gt;弹框宽度 | string | - | '600px' |
| columnCheckModalAppendToBody | 列编辑dialog模式-&gt;弹框蒙层appendToBody | boolean | - | true |
| columnCheckModal | 列编辑dialog模式-&gt;弹框是否显示蒙层 | boolean | - | true |
| columnCheckFullscreen | 列编辑dialog模式-&gt;弹框是否全屏 | boolean | - | false |
| columnCheckTop | 列编辑dialog模式-&gt;弹框Top | string | - | '15vh' |
| columnCheckAppendToBody | 列编辑dialog模式-&gt;弹框appendToBody | boolean | - | false |
| columnCheckLockScroll | 列编辑dialog模式-&gt;弹框LockScroll | boolean | - | true |
| columnCheckCustomClass | 列编辑dialog模式-&gt;弹框CustomClass | string | - | '' |
| columnCheckCloseOnlickModal | 列编辑dialog模式-&gt;弹框CloseOnlickModal | boolean | - | true |
| columnCheckCloseOnPressEscape | 列编辑dialog模式-&gt;弹框CloseOnPressEscape | boolean | - | true |
| columnCheckShowClose | 列编辑dialog模式-&gt;弹框标题ShowClose | boolean | - | true |
| columnCheckBeforeClose | 列编辑dialog模式-&gt;弹框beforeClose | Function | - | undefined |
| columnCheckCenter | 列编辑dialog模式-&gt;弹框是否居中 | boolean | - | false |
| columnCheckDestroyOnClose | 列编辑dialog模式-&gt;弹框销毁是否删除子dom | boolean | - | false |
| columnCheckTabs | 列编辑drawer模式-&gt;tab 的数据 | ITabItem[] | - | - |
| columnCheckCurrentTab | 列编辑drawer模式-&gt;当前显示的 tab 名称 | string | - | - |
| selectEmptyWarningTips | 列编辑设置字段选中未空的提示 | string | - | 请选择至少一个选项 |
| columnCheckSearchPlaceholder | 列编辑drawer模式-&gt;搜索框placeholder | string | - | '搜索' |
| columnCheckFixedLeftDesc | 列编辑drawer模式-&gt;固定在左侧描述 | string | - | 跟随语言包 |
| columnCheckClearDesc | 列编辑drawer模式-&gt;清除描述 | string | - | 跟随语言包 |
| columnCheckNoFixedDesc | 列编辑drawer模式-&gt;不固定描述 | string | - | 跟随语言包 |
| columnCheckGetCheckedLengthDesc | 列编辑drawer模式-&gt;已选描述 | (length) =&gt; string | - | (length) =&gt; '已选（' + length + '）' |
| columnCheckGetAllCheckDesc | 列编辑drawer模式-&gt;全选描述 | (length) =&gt; string | - | (length) =&gt; '全选（' + length + '） |
| virtualized | 启用固定行高的虚拟滚动。 | boolean | — | false |
| virtualTableData | 虚拟表格完整数据源；未设置时使用 data。 | Record&lt;string, any&gt;[] | — | undefined |
| virtualProps | 虚拟窗口配置：rowHeight／itemSize、height、buffer。 | object | — | {} |
| emptyText | 空状态文本。 | string | — | 跟随语言包 |
| viewIdentity | 视图或用户配置标识。 | string | — | undefined |
| detectResize | 保留兼容属性；容器布局由 ResizeObserver 自动监听。 | boolean | — | false |
| drawerProps | 透传列设置抽屉属性。 | object | — | {} |

## Attribute 简易配置 {#easy-config}

| 参数 | 说明 | 类型 | 可选值 | 默认值 |
| --- | --- | --- | --- | --- |
| initSearchApi | true | — | — | — |
| pageChangeSearchApi | true | — | — | — |
| searchFormAttrs.labelWidth | 80 | — | — | — |
| searchFormAttrs.columns | 4 | — | — | — |
| searchFormAttrs.btnModel | inline | — | — | — |
| searchFormAttrs.columnEdit | true | — | — | — |
| tableAttrs.row-key | id | — | — | — |

## Methods {#methods}

| 方法名 | 说明 | 参数 |
| --- | --- | --- |
| clearSelection | 用于多选表格，清空用户的选择 | — |
| toggleRowSelection | 用于多选表格，切换某一行的选中状态，如果使用了第二个参数，则是设置这一行选中与否（selected 为 true 则选中） | row, selected |
| toggleAllSelection | 用于多选表格，切换所有行的选中状态 | — |
| toggleRowExpansion | 用于可展开表格与树形表格，切换某一行的展开状态，如果使用了第二个参数，则是设置这一行展开与否（expanded 为 true 则展开） | row, expanded |
| setCurrentRow | 用于单选表格，设定某一行为选中行，如果调用时不加参数，则会取消目前高亮行的选中状态。 | row |
| clearSort | 用于清空排序条件，数据会恢复成未排序的状态 | — |
| clearFilter | 不传入参数时用于清空所有过滤条件，数据会恢复成未过滤的状态，也可传入由columnKey组成的数组以清除指定列的过滤条件 | columnKey |
| doLayout | 对 Table 进行重新布局。当 Table 或其祖先元素由隐藏切换为显示时，可能需要调用此方法 | — |
| sort | 手动对 Table 进行排序。参数prop属性指定排序列，order指定排序顺序。 | prop: string, order: string |
| resetNfSearchFormModel | 手动执行reset | — |
| onNfSearchFormValidate | 手动执行validate | callback: Function |
| onNfSearchFormSearch | 手动执行search | — |
| onNfSearchFormExport | 手动执行export | — |
| getSelectionRows() | 获取当前选中行。 | — |

## Event {#events}

| 事件名称 | 说明 | 回调参数 |
| --- | --- | --- |
| tableEvents | 表格事件 跟el-table组件Table Events一致 | — |
| pageEvents | 分页事件 跟el-pagination组件Events一致 | — |
| searchFormEvents | 表单事件 跟nf-search-form组件Events一致 | — |
| NfTableActionBtnAttributes.events | actionBtnbar按钮事件 | — |
| columns[i].operationList[i].onClick | 操作功能单元格按钮click事件 | — |
| changeTab | 切换多个drawer tab | name |
| cancel | 关闭drawer tab | Event |
| searchApi | 与searchFormEvents.onSearch雷同, 参数些许变化 | { data: nfSearchForm.getFormData(), callback: 用于关闭列表loading } |
| fixedColumnDragEnd | 固定右侧操作列（自定义句柄）拖拽结束 | { width: number, oldWidth: number, prop?: string, column?: any, nativeEvent?: Event } |
| fieldsChange | 表格显示字段变化。 | columns: string[] |
| update:showColumn | 用于 v-model:showColumn。 | columns: string[] |
| update:actionBarOptList | 操作栏控件值变化。 | items: NfTableActionBtnAttributes[] |
| options-error | 异步列选项加载失败。 | (error, prop: string) |

## Slot {#slots}

| 名称 | 说明 |
| --- | --- |
| append | 插入至表格最后一行之后的内容，如果需要对表格的内容进行无限滚动操作，可能需要用到这个 slot。若表格有合计行，该 slot 会位于合计行之上。 |
| empty | 表格数据为空的定制 |
| searchBox | 表格上方搜索功能定制 |
| actionBar | 表格左下角actionBar功能定制 |
| columnEdit | 列目编辑功能定制 |
| pagination | 分页功能定制 |
| btnBox | nf-search-form slot，兼容ai-search-form扩展操作按钮 |
| columns[i].headerSlot | 每个tableItem表头功能定制 |
| columns[i].slot | 每个tableItem内容功能定制 |
| columns[i].singleHeadMutiColSlot | 每个tableItem嵌套表头功能定制 |
| searchFormColumnEditDialogTitle | nf-search-form列目编辑功能dialog/drawer的title |
| searchFormColumnEditDialogFooter | nf-search-form列目编辑功能dialog/drawer的footer |
| tableColumnEditDialogTitle | nf-table列目编辑功能dialog/drawer的title |
| tableColumnEditDialogFooter | nf-table列目编辑功能dialog/drawer的footer |
| operation | 操作列；接收 row、column、index、$index。 |
| operationIconColumnCheck | 定制嵌入操作列表头的字段设置入口。 |
| NfSearchFormItemOption.slot | 透传搜索表单字段插槽；接收 formData、value、update。 |

## Expose {#expose}

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| localShowItems | string[] | 列编辑显示的列prop |
| tableColumns | NfTableColumnAttributes[] | 渲染表格项 |
| syncLocalShowColumnToCookies | Function | 列编辑同步组件到IndexedDB |
| syncCookiesToLocalShowColumn | Function | 列编辑同步IndexedDB到组件localShowItems |
| syncCookiesToTableColumn | Function | syncCookiesToLocalShowColumn |
| syncShowItemToInitHidden | Function | showItems同步props.formOptions[i].initHidden |
| resetNfSearchFormModel | Function | 重置 |
| onNfSearchFormValidate | Function | 校验 |
| onNfSearchFormSearch | Function | 搜索 |
| onNfSearchFormExport | Function | 导出 |
| nfColumCheckDialogVisible | Boolean | 列编辑控制dialog/drawer显示/隐藏 |
| clearFilter | Function | 表格clearFilter |
| sort | Function | 表格sort |
| doLayout | Function | 表格doLayout |
| clearSort | Function | 表格clearSort |
| setCurrentRow | Function | 表格setCurrentRow |
| toggleRowExpansion | Function | 表格toggleRowExpansion |
| toggleAllSelection | Function | 表格toggleAllSelection |
| toggleRowSelection | Function | 表格toggleRowSelection |
| clearSelection | Function | 表格clearSelection |
| nfTableRef | Ref | 表格nf-table ref(div) |
| elTableRef | Ref | 表格el-table ref |
| nfTableActionContainerRef | Ref | 表格actionBar ref(div) |
| nfTableActionBarRef | Ref | 表格actionBar ref(slot) |
| nfTablePaginationRef | Ref | 表格pagination ref |
| nfSearchFormRef | Ref | 表单nf-search-form ref |
| loadingInstance | Instance | loadingInstance |
| isLoading | boolean | 表格loading状态 |
| columnCheckNfDrawer | Ref | 列编辑nf-drawer ref |
| columnCheckDialog | Ref | 列编辑column-check-dialog ref |
| columnCheckDrawer | Ref | 列编辑column-check-drawer ref |
| showData | Record | 分页数据（处理前端分页和后端分页） |

## 使用说明 {#configuration-notes}

searchApi({data, callback}) 接收转换后的表单数据及分页参数，成功或失败都应在 finally 中调用 callback。省略 pageAttrs.total 使用前端分页，传入 total 时由业务方返回当前页数据；异步请求应避免旧响应覆盖新查询。

虚拟表格使用固定行高窗口与稳定 row-key，不再依赖 Vue 2 的虚拟表格插件。树形展开、合并行及可变行高使用普通模式。列设置及旧 Cookies 命名方法实际使用 IndexedDB。所有示例均在文档内预览，浮层不会被 iframe 裁剪。
