Getting Rid of Spare Rows to Process Table

I have a Handsontable in a React JS application. Currently there are 2 actions that the table is used for:

  1. Processing the data in some calculations
  2. Saving the data to the database.

I have minSpareRows set to 1 in the table, and the table’s “data” is tied to the application’s State. So, whenever I process or save data, it always includes a spare row in the data set being processed. So, my question is, what’s the cleanest way to exclude the “spare row (or, empty row)” from the data set when I’m doing things with it? Here is how I’m defining my table (kind of… I removed a bunch of junk to make it more succinct):

constructor(props) {
super(props);
const myState = this.props.state;
this.state.hotSettings = {
data: myState.ChildRows,
width: “80%”,
height: 200,
rowHeaders: true,
colHeaders: Object.keys(myState.ChildRows[0]),
columns: this.assembleColumns(),
minSpareRows: 1,
contextMenu: true
};
}
this.assembleColumns = () => {
return [{ data: “My Field” }];
}

EDIT: Oh, and here’s how I’m prepping the data to be processed:

runScripts = () => {
const processProps = this.props;
var promise = new Promise(function (resolve, reject) {
generateScripts(processProps.state, “standard”, processProps.currentUser)
resolve(true);
})
promise.then(bool => this.setState({ displayScripts: true }));
}

Hey @xChristine7714

Do you want to export the data to the server without the spare row or you need it to any other operations as well?

I need to perform other operations as well. This application is to generate powershell scripts based on parameters entered into the grid. So, the records are passed to that method to be processed, and I don’t want it to process the blank row.

I hacked together a solution that will go through each record and filter out the ones where all values in the element are blank… but, I don’t know if this is the preferred way to do it.

myRecords = myRecords.filter(f => !isEmpty(f));

function isEmpty(o) {
for (var k in o) {
if (o[k] !== “” && o[k] !== null) return false;
}
return true;
}

Currently it might be an only option as minSpareRows and minSpareCols are a part of the dataset. We’re planning to change that in the future but doesn’t have any fixed date for it.

ps. there are also two methods that may come in handy
https://handsontable.com/docs/6.2.2/Core.html#isEmptyRow
https://handsontable.com/docs/6.2.2/Core.html#countEmptyRows