复选框&单选按钮
复选框
源码
vue
<template>
<div class="base-view">
<div>行: {{ list.length }} 列: {{ columns.length }}</div>
<div style="width: 100%; height: 600px; border: 2px solid var(--color-border)">
<Grid :columns="columns" :list="list" border></Grid>
</div>
</div>
</template>
<script setup lang="ts">
import { Grid, type ListItem, type Column } 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 = 20, 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: 'checkbox', width: 50, fixed: 'left' },
{ type: 'checkbox', width: 50, fixed: 'left' },
...generateColumns(20),
];
const list: ListItem[] = generateList(columns, 100000);
</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 style="width: 100%; height: 600px; border: 2px solid var(--color-border)">
<Grid :columns="columns" :list="list" border></Grid>
</div>
</div>
</template>
<script setup lang="ts">
import { Grid, type ListItem, type Column } 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 = 20, 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: 'checkbox', width: 50, fixed: 'left' },
{ type: 'checkbox', width: 200, fixed: 'left', field: 'checkbox', title: '复选框1' },
// { type: 'checkbox', width: 200, fixed: 'left', field: 'checkbox', title: '复选框2' },
...generateColumns(20),
];
const list: ListItem[] = generateList(columns, 5000);
</script>
<style lang="scss">
.base-view {
width: 100%;
height: 100%;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
}
</style>
单选按钮
源码
vue
<template>
<div class="base-view">
<div style="width: 100%; height: 600px; border: 2px solid var(--color-border)">
<Grid :columns="columns" :list="list" border></Grid>
</div>
</div>
</template>
<script setup lang="ts">
import { Grid, type ListItem, type Column } 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 = 20, 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: 'radio', width: 80, fixed: 'left', title: '单选' },
{ type: 'radio', width: 200, fixed: 'left', title: '带label', field: 'radio' },
...generateColumns(20),
];
const list: ListItem[] = generateList(columns, 5000);
</script>
<style lang="scss">
.base-view {
width: 100%;
height: 100%;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
}
</style>