Group of Rows
Jspreadsheet allows the creation of collapsible groups of rows, which can help manage the available space in the workspace and quickly show or hide the rows within the group. This feature can be helpful when dealing with large datasets or when you want to organize similar rows more compactly and efficiently.
Documentation
Methods
You can programmatically use one of the following methods to manage and interact with the group of rows feature.
Method | Description |
---|---|
getRowGroup() | Get all row groups.getRowGroup() : object |
setRowGroup(number, number) | Create a new collapsable group of rows.setRowGroup(rowNumber: Number, numOfItems: Number) : void |
resetRowGroup(number) | Reset the row group.resetRowGroup(rowNumber: Number) : void |
openRowGroup(number) | Open a group of rows.openRowGroup(rowNumber: Number) : void |
closeRowGroup(number) | Close a group of rows.closeRowGroup(rowNumber: Number) : void |
Events
The following are the available event methods related to the row grouping feature.
Property | Description |
---|---|
ongrouprow | When the user creates, updates or reset a group of rowsoncreaterowgroup?: (worksheet: Object, row: Number, numOfItems: Number) => void |
onopenrowgroup | When the user opens a group of rowsonopenrowgroup?: (worksheet: Object, row: Number) => void |
oncloserowgroup | When the user closes a group of rowsoncloserowgroup?: (worksheet: Object, row: Number) => void |
Initial Settings
You can use one of the following properties to configure the data grid to display specific sets of rows upon initialization.
Property | Description |
---|---|
group?: number | The number of rows. |
state?: boolean | Initial state of this group. Default: false (closed) |
Examples
Basic collapsable row group.
How to create a data grid collapse rows on Jspreadsheet.
<html>
<script src="https://jspreadsheet.com/v10/jspreadsheet.js"></script>
<script src="https://jsuites.net/v5/jsuites.js"></script>
<link rel="stylesheet" href="https://jsuites.net/v5/jsuites.css" type="text/css" />
<link rel="stylesheet" href="https://jspreadsheet.com/v10/jspreadsheet.css" type="text/css" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Material+Icons" />
<div id="spreadsheet"></div>
<input type="button" value="setRowGroup(0,3)" id="setgroup"/>
<input type="button" value="resetRowGroup(0)" id="resetgroup"/>
<script>
// Set your JSS license key (The following key only works for one day)
jspreadsheet.setLicense('N2I0M2M1Y2YyNmUzMDMwOTZkYzg3NDExMGY0ZDEwYzFkY2I1YTMwOTBhMTE5Y2M3ODg1ZWZjODY1YWJiYTJlZjYxNTIyMTg2YjFhODI2YTAzODdjMDlhZjMzYzhhMWFiMTRmYzIzMDFhM2FhN2Y1MmYxYjcyNzM3MTc3OGMxZGQsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpNME9EWTROakV4TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0ozWldJaUxDSnNiMk5oYkdodmMzUWlYU3dpY0d4aGJpSTZJak0wSWl3aWMyTnZjR1VpT2xzaWRqY2lMQ0oyT0NJc0luWTVJaXdpZGpFd0lpd2lkakV4SWl3aVkyaGhjblJ6SWl3aVptOXliWE1pTENKbWIzSnRkV3hoSWl3aWNHRnljMlZ5SWl3aWNtVnVaR1Z5SWl3aVkyOXRiV1Z1ZEhNaUxDSnBiWEJ2Y25SbGNpSXNJbUpoY2lJc0luWmhiR2xrWVhScGIyNXpJaXdpYzJWaGNtTm9JaXdpY0hKcGJuUWlMQ0p6YUdWbGRITWlMQ0pqYkdsbGJuUWlMQ0p6WlhKMlpYSWlMQ0p6YUdGd1pYTWlYU3dpWkdWdGJ5STZkSEoxWlgwPQ==');
// Create the data
// Data
let data = [];
for (let j = 0; j < 50; j++) {
data[j] = [];
for (let i = 0; i < 50; i++) {
data[j][i] = jspreadsheet.helpers.getColumnNameFromCoords(i, j);
}
}
// Create a new spreadsheet
let spreadsheet = jspreadsheet(document.getElementById('spreadsheet'), {
worksheets: [{
data: data,
tableOverflow: true,
tableWidth: '800px',
tableHeight: '400px',
rows: { 6: { group: 3 }},
}]
});
document.getElementById("setgroup").onclick = () => spreadsheet[0].setRowGroup(0,3);
document.getElementById("resetgroup").onclick = () => spreadsheet[0].resetRowGroup(0);
</script>
</html>
import React, { useRef } from "react";
import { Spreadsheet, Worksheet } from "@jspreadsheet/react";
import jspreadsheet from "jspreadsheet";
const license = 'N2I0M2M1Y2YyNmUzMDMwOTZkYzg3NDExMGY0ZDEwYzFkY2I1YTMwOTBhMTE5Y2M3ODg1ZWZjODY1YWJiYTJlZjYxNTIyMTg2YjFhODI2YTAzODdjMDlhZjMzYzhhMWFiMTRmYzIzMDFhM2FhN2Y1MmYxYjcyNzM3MTc3OGMxZGQsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpNME9EWTROakV4TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0ozWldJaUxDSnNiMk5oYkdodmMzUWlYU3dpY0d4aGJpSTZJak0wSWl3aWMyTnZjR1VpT2xzaWRqY2lMQ0oyT0NJc0luWTVJaXdpZGpFd0lpd2lkakV4SWl3aVkyaGhjblJ6SWl3aVptOXliWE1pTENKbWIzSnRkV3hoSWl3aWNHRnljMlZ5SWl3aWNtVnVaR1Z5SWl3aVkyOXRiV1Z1ZEhNaUxDSnBiWEJ2Y25SbGNpSXNJbUpoY2lJc0luWmhiR2xrWVhScGIyNXpJaXdpYzJWaGNtTm9JaXdpY0hKcGJuUWlMQ0p6YUdWbGRITWlMQ0pqYkdsbGJuUWlMQ0p6WlhKMlpYSWlMQ0p6YUdGd1pYTWlYU3dpWkdWdGJ5STZkSEoxWlgwPQ==';
export default function App() {
// Spreadsheet array of worksheets
const spreadsheet = useRef();
// Data
let data = [];
for (let j = 0; j < 50; j++) {
data[j] = [];
for (let i = 0; i < 50; i++) {
data[j][i] = jspreadsheet.helpers.getColumnNameFromCoords(i, j);
}
}
// Rows settings
const rows = { 6: { group: 3 }}
// Render component
return (
<>
<Spreadsheet ref={spreadsheet} license={license}>
<Worksheet
data={data}
tableOverflow
tableWidth="800px"
tableHeight="400px"
rows={rows} />
</Spreadsheet>
<input type="button" value="setRowGroup(0,3)" onClick={() => spreadsheet.current[0].setRowGroup(0,3)} />
<input type="button" value="resetRowGroup(0)" onClick={() => spreadsheet.current[0].resetRowGroup(0)} />
</>
);
}
<template>
<Spreadsheet ref="spreadsheet" :license="license">
<Worksheet :data="data" :rows="rows" tableOverflow tableWidth="800px" tableHeight="400px" />
</Spreadsheet>
<input type="button" value="setRowGroup(0,3)" @click="setRowGroup(0,3)" />
<input type="button" value="resetRowGroup(0)" @click="resetRowGroup(0);" />
</template>
<script>
import { Spreadsheet, Worksheet, jspreadsheet } from "@jspreadsheet/vue";
const license = 'N2I0M2M1Y2YyNmUzMDMwOTZkYzg3NDExMGY0ZDEwYzFkY2I1YTMwOTBhMTE5Y2M3ODg1ZWZjODY1YWJiYTJlZjYxNTIyMTg2YjFhODI2YTAzODdjMDlhZjMzYzhhMWFiMTRmYzIzMDFhM2FhN2Y1MmYxYjcyNzM3MTc3OGMxZGQsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpNME9EWTROakV4TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0ozWldJaUxDSnNiMk5oYkdodmMzUWlYU3dpY0d4aGJpSTZJak0wSWl3aWMyTnZjR1VpT2xzaWRqY2lMQ0oyT0NJc0luWTVJaXdpZGpFd0lpd2lkakV4SWl3aVkyaGhjblJ6SWl3aVptOXliWE1pTENKbWIzSnRkV3hoSWl3aWNHRnljMlZ5SWl3aWNtVnVaR1Z5SWl3aVkyOXRiV1Z1ZEhNaUxDSnBiWEJ2Y25SbGNpSXNJbUpoY2lJc0luWmhiR2xrWVhScGIyNXpJaXdpYzJWaGNtTm9JaXdpY0hKcGJuUWlMQ0p6YUdWbGRITWlMQ0pqYkdsbGJuUWlMQ0p6WlhKMlpYSWlMQ0p6YUdGd1pYTWlYU3dpWkdWdGJ5STZkSEoxWlgwPQ==';
// Data
let data = [];
for (let j = 0; j < 50; j++) {
data[j] = [];
for (let i = 0; i < 50; i++) {
data[j][i] = jspreadsheet.helpers.getColumnNameFromCoords(i, j);
}
}
export default {
components: {
Spreadsheet,
Worksheet,
},
methods: {
setRowGroup(row, numOfRows) {
this.$refs.spreadsheet.current[0].setRowGroup(row, numOfRows);
},
resetRowGroup(row) {
this.$refs.spreadsheet.current[0].resetRowGroup(row);
},
},
data() {
return {
// Worksheet data
data: data,
// Rows
rows: { 6: { group: 3 }},
// License
license: license,
};
}
}
</script>
import { Component, ViewChild, ElementRef } from "@angular/core";
import jspreadsheet from "jspreadsheet";
import "jspreadsheet/dist/jspreadsheet.css"
import "jsuites/dist/jsuites.css"
// Set your JSS license key (The following key only works for one day)
jspreadsheet.setLicense('N2I0M2M1Y2YyNmUzMDMwOTZkYzg3NDExMGY0ZDEwYzFkY2I1YTMwOTBhMTE5Y2M3ODg1ZWZjODY1YWJiYTJlZjYxNTIyMTg2YjFhODI2YTAzODdjMDlhZjMzYzhhMWFiMTRmYzIzMDFhM2FhN2Y1MmYxYjcyNzM3MTc3OGMxZGQsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpNME9EWTROakV4TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0ozWldJaUxDSnNiMk5oYkdodmMzUWlYU3dpY0d4aGJpSTZJak0wSWl3aWMyTnZjR1VpT2xzaWRqY2lMQ0oyT0NJc0luWTVJaXdpZGpFd0lpd2lkakV4SWl3aVkyaGhjblJ6SWl3aVptOXliWE1pTENKbWIzSnRkV3hoSWl3aWNHRnljMlZ5SWl3aWNtVnVaR1Z5SWl3aVkyOXRiV1Z1ZEhNaUxDSnBiWEJ2Y25SbGNpSXNJbUpoY2lJc0luWmhiR2xrWVhScGIyNXpJaXdpYzJWaGNtTm9JaXdpY0hKcGJuUWlMQ0p6YUdWbGRITWlMQ0pqYkdsbGJuUWlMQ0p6WlhKMlpYSWlMQ0p6YUdGd1pYTWlYU3dpWkdWdGJ5STZkSEoxWlgwPQ==');
// Data
let data = [];
for (let j = 0; j < 50; j++) {
data[j] = [];
for (let i = 0; i < 50; i++) {
data[j][i] = jspreadsheet.helpers.getColumnNameFromCoords(i, j);
}
}
@Component({
selector: "app-root",
template: `
<div #spreadsheet></div>
<input type="button" value="setRowGroup(0,3)" (click)="this.worksheets[0].setRowGroup(0,3)" />
<input type="button" value="resetRowGroup(0)" (click)="this.worksheets[0].resetRowGroup(0);" />`
})
export class AppComponent {
@ViewChild("spreadsheet") spreadsheet: ElementRef;
// Worksheets
worksheets: jspreadsheet.worksheetInstance[];
// Create a new data grid
ngAfterViewInit() {
// Create spreadsheet
this.worksheets = jspreadsheet(this.spreadsheet.nativeElement, {
worksheets: [{
data: data,
tableOverflow: true,
tableWidth: '800px',
tableHeight: '400px',
rows: { 6: { group: 3 }},
}]
});
}
}