vue2项目请移步@94ai/common-ui
LLMs.md

nf-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'

简易配置 ​

正在加载示例…
简易配置

纯数据定制 ​

正在加载示例…
纯数据定制

各种slot定制+固定列 ​

正在加载示例…
各种slot定制+固定列

数据加slot ​

正在加载示例…
数据加slot

边框表格和表头嵌套 ​

正在加载示例…
边框表格和表头嵌套

表格排序+筛选 ​

正在加载示例…
表格排序+筛选

展开行和树形数据 ​

正在加载示例…
展开行和树形数据

无分页的虚拟表格 ​

正在加载示例…
无分页的虚拟表格

固定右侧操作列拖拽与指示线边界 ​

正在加载示例…
固定右侧操作列拖拽与指示线边界

NfTableColumnAttributes ​

参数说明类型
key列的唯一标识;未设置 prop 时用作回退标识。string / number
prop列字段路径。string
type选择列、序号列或展开列。selection / index / expand
label列标题,也可由函数返回。string / Function
attrElement Plus TableColumn 公开属性。ElTableColumnAttributes
slot单元格具名插槽。string
headerSlot表头具名插槽。string
singleHeadMutiColSlot单个表头下嵌套 TableColumn 插槽。string
children嵌套表头列定义。NfTableColumnAttributes[]
render使用 Vue 3 h 或 VNode 定制单元格。(row, scope) => 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 ​

参数说明类型可选值默认值
data填充表格数据Record<string, any>[]—[]
columns渲染表头json dataNfTableColumnAttributes[]—[]
searchFormAttrs表单属性,跟nf-search-form Attributes属性一样NfSearchFormAttributes—{}
pageAttrs分页属性。省略 total 使用前端分页;传入 total 使用服务端分页,业务方按请求返回当前页数据。ElPaginationAttributes—{}
tableAttrs表格属性,透传 Element Plus Table 的公开属性。ElTableAttributes—{}
searchFormEvents表单事件 跟nf-search-form组件Events一致Partial<Record<NfSearchFormEventKey, Function>>—{}
pageEvents分页事件 跟el-pagination组件Events一致Partial<Record<ElPaginationEventKey, Function>>—{}
tableEvents表格事件 跟el-table组件Table Events一致Partial<Record<ElTableEventKey, Function>>—{}
actionBarOptListactionBar按钮渲染json dataNfTableActionBtnAttributes[]—[]
operationPropKey数据驱动渲染单元格操作按钮,指定单元格的prop值定义为按钮操作列的keystring—'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表格空数据时空组件sizenumber—145
initSearchApi初始化是否自动查询;未传时跟随 setEasyConf。boolean不传则跟随setEasyConfundefined
pageChangeSearchApi分页变化是否自动查询;未传时跟随 setEasyConf。boolean不传则跟随setEasyConfundefined
pageKeys分页使用的字段string[]-['pageNo', 'pageSize']
setEasyConf启用简易配置,提供初始化查询、分页查询、搜索布局及 row-key 默认值,显式设置优先。boolean请查阅false
loading功能
loading表格loadingboolean—false
targetLoading 需要覆盖的 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
textLoading 显示在加载图标下方的加载文案string—undefined
spinnerLoading 自定义加载图标类名string—undefined
backgroundLoading 遮罩背景色string—undefined
customClassLoading 的自定义类名string—undefined
columnEdit列编辑功能开关。boolean—false
columnPosition列编辑按钮位置stringfree/embed'embed'
showColumn列编辑初始化要显示的表格项字段prop集合,[]代表显示所有,可以和columns的initHidden配合使用string[]—undefined
priority列编辑缓存回显优先级,处理item.initHidden,form.showColumn和IndexedDB.cache的回显关系stringcached/value'cached'
storageKey表格列设置的 IndexedDB 缓存键;同页多实例应使用独立键。string-nf-table-columns-cached-key-${routeName}
searchFormStorageKey可选,含义同storageKey,nfSearchForm设置字段缓存key,也可以在searchFormAttrs设置storageKeystring-nf-search-form-columns-cached-key-${routeName}
checkMode可选,列编辑交互模式,默认drawer(drawer/dialog)stringdialog/drawer'drawer'
columnDisplayBtnClass列编辑按钮类名string—''
columnDisplayBtnIcon列编辑按钮图标string—undefined
columnDisplayBtnType列编辑按钮类型string—'primary'
columnDisplayBtnPlain列编辑按钮镂空boolean—true
columnDisplayBtnSize列编辑按钮尺寸string—'mini'
columnDisplayBtnRound列编辑按钮圆角boolean—false
columnDisplayBtnCircle列编辑按钮圆形boolean—false
columnDisplayBtnLoading列编辑按钮Loadingboolean—false
columnDisplayBtnDisabled列编辑按钮禁用boolean—false
columnDisplayBtnText列编辑按钮文本string—跟随语言包
columnCheckTitle列编辑dialog/drawer模式->弹框标题string-设置显示字段
columnCheckCancelButtonText列编辑dialog/drawer模式取消按钮文本string-'取消'
columnCheckConfirmButtonText列编辑dialog/drawer模式确定按钮文本string-'确定'
columnCheckBasicFieldDesc默认category分类标题string-跟随语言包
columnCheckWidth列编辑dialog模式->弹框宽度string-'600px'
columnCheckModalAppendToBody列编辑dialog模式->弹框蒙层appendToBodyboolean-true
columnCheckModal列编辑dialog模式->弹框是否显示蒙层boolean-true
columnCheckFullscreen列编辑dialog模式->弹框是否全屏boolean-false
columnCheckTop列编辑dialog模式->弹框Topstring-'15vh'
columnCheckAppendToBody列编辑dialog模式->弹框appendToBodyboolean-false
columnCheckLockScroll列编辑dialog模式->弹框LockScrollboolean-true
columnCheckCustomClass列编辑dialog模式->弹框CustomClassstring-''
columnCheckCloseOnlickModal列编辑dialog模式->弹框CloseOnlickModalboolean-true
columnCheckCloseOnPressEscape列编辑dialog模式->弹框CloseOnPressEscapeboolean-true
columnCheckShowClose列编辑dialog模式->弹框标题ShowCloseboolean-true
columnCheckBeforeClose列编辑dialog模式->弹框beforeCloseFunction-undefined
columnCheckCenter列编辑dialog模式->弹框是否居中boolean-false
columnCheckDestroyOnClose列编辑dialog模式->弹框销毁是否删除子domboolean-false
columnCheckTabs列编辑drawer模式->tab 的数据ITabItem[]--
columnCheckCurrentTab列编辑drawer模式->当前显示的 tab 名称string--
selectEmptyWarningTips列编辑设置字段选中未空的提示string-请选择至少一个选项
columnCheckSearchPlaceholder列编辑drawer模式->搜索框placeholderstring-'搜索'
columnCheckFixedLeftDesc列编辑drawer模式->固定在左侧描述string-跟随语言包
columnCheckClearDesc列编辑drawer模式->清除描述string-跟随语言包
columnCheckNoFixedDesc列编辑drawer模式->不固定描述string-跟随语言包
columnCheckGetCheckedLengthDesc列编辑drawer模式->已选描述(length) => string-(length) => '已选(' + length + ')'
columnCheckGetAllCheckDesc列编辑drawer模式->全选描述(length) => string-(length) => '全选(' + length + ')
virtualized启用固定行高的虚拟滚动。boolean—false
virtualTableData虚拟表格完整数据源;未设置时使用 data。Record<string, any>[]—undefined
virtualProps虚拟窗口配置:rowHeight/itemSize、height、buffer。object—{}
emptyText空状态文本。string—跟随语言包
viewIdentity视图或用户配置标识。string—undefined
detectResize保留兼容属性;容器布局由 ResizeObserver 自动监听。boolean—false
drawerProps透传列设置抽屉属性。object—{}

Attribute 简易配置 ​

参数说明类型可选值默认值
initSearchApitrue———
pageChangeSearchApitrue———
searchFormAttrs.labelWidth80———
searchFormAttrs.columns4———
searchFormAttrs.btnModelinline———
searchFormAttrs.columnEdittrue———
tableAttrs.row-keyid———

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手动执行validatecallback: Function
onNfSearchFormSearch手动执行search—
onNfSearchFormExport手动执行export—
getSelectionRows()获取当前选中行。—

Event ​

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

Slot ​

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

Expose ​

名称类型说明
localShowItemsstring[]列编辑显示的列prop
tableColumnsNfTableColumnAttributes[]渲染表格项
syncLocalShowColumnToCookiesFunction列编辑同步组件到IndexedDB
syncCookiesToLocalShowColumnFunction列编辑同步IndexedDB到组件localShowItems
syncCookiesToTableColumnFunctionsyncCookiesToLocalShowColumn
syncShowItemToInitHiddenFunctionshowItems同步props.formOptions[i].initHidden
resetNfSearchFormModelFunction重置
onNfSearchFormValidateFunction校验
onNfSearchFormSearchFunction搜索
onNfSearchFormExportFunction导出
nfColumCheckDialogVisibleBoolean列编辑控制dialog/drawer显示/隐藏
clearFilterFunction表格clearFilter
sortFunction表格sort
doLayoutFunction表格doLayout
clearSortFunction表格clearSort
setCurrentRowFunction表格setCurrentRow
toggleRowExpansionFunction表格toggleRowExpansion
toggleAllSelectionFunction表格toggleAllSelection
toggleRowSelectionFunction表格toggleRowSelection
clearSelectionFunction表格clearSelection
nfTableRefRef表格nf-table ref(div)
elTableRefRef表格el-table ref
nfTableActionContainerRefRef表格actionBar ref(div)
nfTableActionBarRefRef表格actionBar ref(slot)
nfTablePaginationRefRef表格pagination ref
nfSearchFormRefRef表单nf-search-form ref
loadingInstanceInstanceloadingInstance
isLoadingboolean表格loading状态
columnCheckNfDrawerRef列编辑nf-drawer ref
columnCheckDialogRef列编辑column-check-dialog ref
columnCheckDrawerRef列编辑column-check-drawer ref
showDataRecord分页数据(处理前端分页和后端分页)

使用说明 ​

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

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