表格搜索
启用内置搜索功能,使用 Cmd/Ctrl+F 打开搜索框查找单元格内容。
示例
微应用尚未挂载。
源码
点击查看源码
ts
import { faker } from '@faker-js/faker';
import { VirtTable } from '@virt-table/vanilla';
import { vtSearch } from '@virt-table/vanilla/plugins';
export function bootstrapTableSearch(root: HTMLElement): () => void {
const colCount = 10;
const rowCount = 1000;
const columns = Array.from({ length: colCount }, (_, i) => ({
key: `extra_${i}`,
title: `列 ${i}`,
width: 200,
}));
const list = Array.from({ length: rowCount }, (_, i) => {
const row: Record<string, any> = { id: i };
for (let c = 0; c < colCount; c++) {
row[`extra_${c}`] = `${i}-${c}-${faker.lorem.words(6)}`;
}
return row;
});
root.innerHTML = '<div style="width:800px;height:600px;" class="demo-container" id="tableContainer"></div>';
const container = root.querySelector('#tableContainer') as HTMLElement;
const table = new VirtTable(container, {
list,
columns,
itemKey: 'id',
estimatedSize: 40,
buffer: 4,
plugins: [vtSearch()],
border: true,
});
return () => {
table.destroy();
root.innerHTML = '';
};
}相关 API
| 字段 / 方法 | 作用 | 详见 |
|---|---|---|
vtSearch() | 全文搜索插件(Cmd/Ctrl+F 打开) | 插件机制 |
--vt-highlight-bg / --vt-highlight-border | 命中高亮配色 | 主题定制 |
locale.search | 搜索框文案 | 表格配置 · i18n |