React VtNumberInput 数字输入
数字输入列:与 VtInput 同构,编辑态是数字输入框,另有取值范围、步进与小数位数。
编辑态走 renderEditor,必须装 vtCellEditor 插件才会被触发。
示例
微应用尚未挂载。
源码
点击查看源码
tsx
import { VirtTableReact, type ReactTableColumn, vtCellEditor } from '@virt-table/react';
import { VtNumberInput } from '@virt-table/vanilla/components';
const ROW_COUNT = 5000;
const columns: ReactTableColumn[] = [
{ key: 'id', title: 'ID', width: 80, align: 'center' },
VtNumberInput({ key: 'score', title: '分数', width: 160, placeholder: '0-100', min: 0, max: 100, step: 1 }),
VtNumberInput({
key: 'price',
title: '价格',
width: 180,
placeholder: '请输入价格',
min: 0,
step: 0.01,
precision: 2,
clearable: true,
}),
VtNumberInput({
key: 'quantity',
title: '数量',
width: 160,
placeholder: '请输入数量',
min: 0,
max: 9999,
step: 1,
clearable: true,
}),
VtNumberInput({ key: 'readonly', title: '只读', width: 160, disabled: true, precision: 2 }),
];
const list = Array.from({ length: ROW_COUNT }, (_, i) => ({
id: i,
score: Math.floor(Math.random() * 100),
price: +(Math.random() * 1000).toFixed(2),
quantity: Math.floor(Math.random() * 500),
readonly: +(Math.random() * 100).toFixed(2),
}));
// 编辑态走 renderEditor,必须装 vtCellEditor 才会被触发
const plugins = [vtCellEditor()];
export default function VtNumberInputTable() {
return (
<div className="demo-wrapper">
<h3 className="demo-title">React VtNumberInput 数字输入</h3>
<div className="status-text">
VtNumberInput 单元格组件:{ROW_COUNT} 行(支持 min/max/step/precision、clearable、disabled)
</div>
<div style={{ width: 760, height: 600 }} className="demo-container">
<VirtTableReact
columns={columns}
options={{
list,
itemKey: 'id',
estimatedSize: 40,
buffer: 4,
border: true,
textOverflow: 'ellipsis',
plugins,
}}
/>
</div>
</div>
);
}相关 API
| 字段 | 作用 |
|---|---|
min / max | 取值范围 |
step / precision | 步进与小数位数 |
全量选项表见 单元格组件;公共选项 (
placeholder/disabled/clearable/onChange)、asCell()、三类交互模型见 同页上方;列的通用字段见 列配置。编辑态需装
vtCellEditor,见 插件机制。上面的字段在 React 端原样透传(实例方法通过组件
ref调用)。封装层特有的部分 —— 组件 Props、渲染函数返回 JSX、ref转发了哪些方法 —— 见 React API。