索引
常规索引
ts
const columns = [
{
type: 'index',
},
];
源码
vue
<template>
<div class="base-view">
<!-- <div>Column.length - {{ columns.length }}; List.length - {{ list.length }}</div> -->
<!-- <div>Render- {{ $refs.grid.gridStore.watchData }}</div> -->
<div style="width: 100%; height: 600px; border: 2px solid var(--color-border)">
<Grid
ref="grid"
:columns="columns"
:list="list"
:options="{
border: true,
}"
></Grid>
</div>
</div>
</template>
<script setup lang="ts">
import { Grid, type Column, type ListItem } from 'vue-virt-grid';
const generateColumns = (length = 10, prefix = 'field-', props?: any) =>
Array.from({ length }).map((_, columnIndex) => ({
...props,
field: `${prefix}${columnIndex}`,
title: `Title ${columnIndex}`,
width: 200,
}));
const generateList = (columns: ReturnType<typeof generateColumns>, length = 200, prefix = 'row-') =>
Array.from({ length }).map((_, rowIndex) => {
return columns.reduce(
(rowData, column, columnIndex) => {
rowData[column.field] = `Row ${rowIndex} - Field ${columnIndex}`;
return rowData;
},
{
id: `${prefix}${rowIndex}`,
parentId: null,
},
);
});
const columns: Column[] = [
{ type: 'index', width: 50, title: '#', fixed: 'left' },
...generateColumns(20),
];
const list: ListItem[] = generateList(columns, 5000);
</script>
<style lang="scss">
.base-view {
width: 100%;
height: 100%;
overflow: hidden;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
</style>
自定义索引
ts
const columns = [
{
type: 'index',
index: (index: number) => `x-${index}`,
},
];
源码
vue
<template>
<div class="base-view">
<!-- <div>Column.length - {{ columns.length }}; List.length - {{ list.length }}</div> -->
<!-- <div>Render- {{ $refs.grid.gridStore.watchData }}</div> -->
<div style="width: 100%; height: 600px; border: 2px solid var(--color-border)">
<Grid
ref="grid"
:columns="columns"
:list="list"
:options="{
border: true,
}"
></Grid>
</div>
</div>
</template>
<script setup lang="ts">
import { Grid, type Column, type ListItem } from 'vue-virt-grid';
const generateColumns = (length = 10, prefix = 'field-', props?: any) =>
Array.from({ length }).map((_, columnIndex) => ({
...props,
field: `${prefix}${columnIndex}`,
title: `Title ${columnIndex}`,
width: 200,
}));
const generateList = (columns: ReturnType<typeof generateColumns>, length = 200, prefix = 'row-') =>
Array.from({ length }).map((_, rowIndex) => {
return columns.reduce(
(rowData, column, columnIndex) => {
rowData[column.field] = `Row ${rowIndex} - Field ${columnIndex}`;
return rowData;
},
{
parentId: null,
},
);
});
const columns: Column[] = [
{ type: 'index', width: 50, title: '#', fixed: 'left', index: (index: number) => `x-${index}` },
...generateColumns(20),
];
const list: ListItem[] = generateList(columns, 5000);
</script>
<style lang="scss">
.base-view {
width: 100%;
height: 100%;
overflow: hidden;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
</style>