索引
常规索引
源码
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" border></Grid>
</div>
</div>
</template>
<script setup lang="ts">
import { Grid, type Column, type ListItem } from 'kita-grid';
const generateColumns = (length = 10, prefix = 'column-', props?: any) =>
Array.from({ length }).map((_, columnIndex) => ({
...props,
field: `${prefix}${columnIndex}`,
title: `Column ${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} - Col ${columnIndex}`;
return rowData;
},
{
id: `${prefix}${rowIndex}`,
parentId: null,
},
);
});
const columns: Column[] = [{ type: 'index', width: 50, 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>
自定义索引
源码
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" border></Grid>
</div>
</div>
</template>
<script setup lang="ts">
import { Grid, type Column, type ListItem } from 'kita-grid';
const generateColumns = (length = 10, prefix = 'column-', props?: any) =>
Array.from({ length }).map((_, columnIndex) => ({
...props,
field: `${prefix}${columnIndex}`,
title: `Column ${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} - Col ${columnIndex}`;
return rowData;
},
{
parentId: null,
},
);
});
const columns: Column[] = [
{ type: 'index', width: 50, 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>