The Row Auto Size Plugin enhances RevoGrid by automatically calculating and adjusting row heights based on their content. This ensures optimal display of data, particularly useful for cells containing multi-line text, rich content, or varying amounts of information.
Key Features
Automatic Height Calculation: Dynamically adjusts row heights based on content.
Content-Aware: Considers line breaks, text wrapping, and column widths.
Configurable Limits: Set minimum and maximum heights to maintain consistency.
Custom Calculator Support: Implement your own height calculation logic.
Efficient Caching: Caches calculated heights to optimize performance.
Precise Mode: Optional precise calculations using DOM measurements.
Basic Setup
To enable the Row Auto Size Plugin in your RevoGrid setup:
You can provide your own height calculation logic through the calculateHeight function:
1
grid.additionalData = {
2
rowAutoSize: {
3
calculateHeight: (rowData, columns) => {
4
// Custom logic to determine row height
5
constmaxLines= columns.reduce((max, col) => {
6
constcontent= rowData[col.prop]?.toString() ||'';
7
constlines= content.split('\n').length;
8
return Math.max(max, lines);
9
}, 1);
10
11
return maxLines *24; // 24px per line
12
}
13
}
14
};
Events and Updates
The plugin automatically responds to various grid events to maintain accurate row heights:
Data Changes: Recalculates heights when the source data is updated
Cell Edits: Updates heights for edited rows
Viewport Changes: Calculates heights for newly visible rows
Configuration Changes: Recomputes all heights when plugin settings change
Performance Considerations
The plugin is designed with performance in mind, but there are some considerations:
Precise Mode: Using preciseSize: true provides more accurate calculations but is slower as it requires DOM operations.
Large Datasets: For large datasets, heights are calculated only for visible rows and cached for better performance.
Custom Calculators: When implementing a custom calculator, ensure it’s efficient as it will be called frequently during scrolling.
Best Practices
Default Mode for Large Datasets: Use the default approximate calculation mode for large datasets to maintain performance.
Precise Mode for Critical Cases: Enable precise calculations only when exact heights are crucial.
Reasonable Limits: Set appropriate minHeight and maxHeight to prevent extreme row sizes.
Cache Management: The plugin automatically manages its cache, but consider clearing it when making major data changes.
Example Use Cases
Multi-line Text:
1
grid.columns = [{
2
prop:'description',
3
name:'Description',
4
size:200,
5
}];
6
grid.source = [{
7
description:'This is a long description\nthat spans multiple lines\nand needs appropriate height'
8
}];
Rich Content:
1
grid.additionalData = {
2
rowAutoSize: {
3
calculateHeight: (rowData) => {
4
if (rowData.hasImage) {
5
return100; // Taller rows for rows with images
6
}
7
return24; // Default height for other rows
8
}
9
}
10
};
Conclusion
The Row Auto Size Plugin provides a powerful solution for handling varying content heights in RevoGrid. By automatically adjusting row heights while maintaining performance, it significantly improves the presentation and usability of your grid, especially when dealing with dynamic or rich content.