// src/components/row-autosize/rowAutosize.ts
import { defineCustomElements } from '@revolist/revogrid/loader';
defineCustomElements();
import {
RowHeaderPlugin,
RowAutoSizePlugin,
} from '@revolist/revogrid-pro';
import { currentTheme } from '../composables/useRandomData';
import { faker } from '@faker-js/faker';
const { isDark } = currentTheme();
// Generate sample data with varying content lengths
const generateData = (count: number) => {
return Array.from({ length: count }, () => ({
name: faker.person.fullName(),
description: Array.from(
{ length: Math.floor(Math.random() * 4) + 1 },
() => faker.lorem.sentence()
).join('\n'),
email: faker.internet.email(),
}));
};
export function load(parentSelector: string) {
const parent = document.querySelector(parentSelector);
if (!parent) return;
const grid = document.createElement('revo-grid');
grid.source = generateData(100);
// Define columns;
grid.columns = [
{
prop: 'name',
name: 'Name',
size: 150,
},
{
prop: 'description',
name: '📝 Description',
size: 300,
},
{
prop: 'email',
name: 'Email',
size: 220,
readonly: true,
},
];
// Define plugin
grid.plugins = [RowHeaderPlugin, RowAutoSizePlugin];
// Configure row auto size
Object.assign(grid, {
rowAutoSize: {
minHeight: 24,
maxHeight: 200,
preciseSize: true,
},
})
grid.theme = isDark() ? 'darkCompact' : 'compact';
grid.hideAttribution = true;
parent.appendChild(grid);
}
import React, { useState, useMemo } from 'react';
import { RevoGrid } from '@revolist/react-datagrid';
import { RowHeaderPlugin, RowAutoSizePlugin } from '@revolist/revogrid-pro';
import { currentTheme } from '../composables/useRandomData';
import { faker } from '@faker-js/faker';
const RowAutosizeGrid = () => {
const { isDark } = currentTheme();
const theme = isDark() ? 'darkCompact' : 'compact';
// Generate sample data with varying content lengths
const generateData = (count: number) => {
return Array.from({ length: count }, () => ({
name: faker.person.fullName(),
description: Array.from(
{ length: Math.floor(Math.random() * 4) + 1 },
() => faker.lorem.sentence()
).join('\n'),
email: faker.internet.email(),
}));
};
const [rows] = useState(() => generateData(100));
const columns = useMemo(
() => [
{
prop: 'name',
name: 'Name',
size: 150,
},
{
prop: 'description',
name: '📝 Description',
size: 300,
},
{
prop: 'email',
name: 'Email',
size: 220,
readonly: true,
},
],
[]
);
const plugins = [RowHeaderPlugin, RowAutoSizePlugin];
const additionalData = {
rowAutoSize: {
minHeight: 24,
maxHeight: 200,
preciseSize: true,
},
};
return (
<RevoGrid
theme={theme}
columns={columns}
source={rows}
plugins={plugins}
additionalData={additionalData}
hideAttribution
/>
);
};
export default RowAutosizeGrid;
<template>
<RevoGrid
class="overflow-hidden cell-border"
:theme="isDark ? 'darkMaterial' : 'material'"
:columns="columns"
:source="rows"
:plugins="plugins"
:additional-data="additionalData"
range
hide-attribution
/>
</template>
<script setup lang="ts">
import { ref, shallowRef } from 'vue';
import RevoGrid from '@revolist/vue3-datagrid';
import {
RowHeaderPlugin,
RowOddPlugin,
RowAutoSizePlugin,
} from '@revolist/revogrid-pro';
import { currentThemeVue } from '../composables/useRandomData';
import { faker } from '@faker-js/faker';
const { isDark } = currentThemeVue();
// Generate sample data with varying content lengths
const generateData = (count: number) => {
return Array.from({ length: count }, () => ({
name: faker.person.fullName(),
description: Array.from(
{ length: Math.floor(Math.random() * 4) + 1 },
() => faker.lorem.sentence()
).join('\n'),
email: faker.internet.email(),
}));
};
const rows = shallowRef(generateData(100));
const columns = ref([
{
prop: 'name',
name: 'Name',
size: 150,
},
{
prop: 'description',
name: '📝 Description',
size: 300,
},
{
prop: 'email',
name: 'Email',
size: 220,
readonly: true,
},
]);
const plugins = [RowHeaderPlugin, RowAutoSizePlugin, RowOddPlugin];
const additionalData = ref({
rowAutoSize: {
minHeight: 24,
maxHeight: 200,
preciseSize: true,
},
});
</script>
import { Component, ViewEncapsulation, OnInit, NO_ERRORS_SCHEMA } from '@angular/core';
import { RevoGrid } from '@revolist/angular-datagrid';
import {
RowHeaderPlugin,
RowAutoSizePlugin,
} from '@revolist/revogrid-pro';
import { currentTheme } from '../composables/useRandomData';
import { faker } from '@faker-js/faker';
@Component({
selector: 'row-autosize-grid',
standalone: true,
imports: [RevoGrid],
template: `
<revo-grid
[theme]="theme"
[columns]="columns"
[source]="rows"
[plugins]="plugins"
[rowAutoSize]="additionalData.rowAutoSize"
[hideAttribution]="true"
style="min-height: 400px; min-width: 600px"
></revo-grid>
`,
encapsulation: ViewEncapsulation.None,
// Allows Angular demos to bind RevoGrid plugin props that are not wrapper inputs.
schemas: [NO_ERRORS_SCHEMA],
})
export class RowAutosizeGridComponent implements OnInit {
theme = currentTheme().isDark() ? 'darkCompact' : 'compact';
// Generate sample data with varying content lengths
generateData(count: number) {
return Array.from({ length: count }, () => ({
name: faker.person.fullName(),
description: Array.from(
{ length: Math.floor(Math.random() * 4) + 1 },
() => faker.lorem.sentence()
).join('\n'),
email: faker.internet.email(),
}));
}
rows = this.generateData(100);
columns = [
{
prop: 'name',
name: 'Name',
size: 150,
},
{
prop: 'description',
name: '📝 Description',
size: 300,
},
{
prop: 'email',
name: 'Email',
size: 220,
readonly: true,
},
];
plugins = [RowHeaderPlugin, RowAutoSizePlugin];
additionalData = {
rowAutoSize: {
minHeight: 24,
maxHeight: 200,
preciseSize: true,
},
};
ngOnInit() {
// Any additional setup if needed
}
}