[GH #4195, #5069] dataSchema and array of arrays (excess minSpreRows)

Tags: #<Tag:0x00007f8b19d37c68> #<Tag:0x00007f8b19d37b28>

Hi everyone,

I try to use a dataSchema with a source as a array of arrays. On every change of any cell I get a extra spare row. Here is a demo.

My question is, is this the right way to use dataSchema for an array of arrays?

Hi @stelo

the solution you took from [GL #153] Extra row added after refresh data

breaks the demo to act like this. When we comment afterInit https://jsfiddle.net/handsoncode/5Lxqoowh/ it works fine.

Hi @aleksandra_budnik

thank you for your demo. This works fine as long minSpareRows is 0 or the data schema contains only null values.

My intention was, to set in a new row default values other then null. If I do so – without the afterInit function –, I get 2 spare rows after the initialization and after every change of a cell a extra spare row like in this demo.

I’m not sure, whether this should work I planned.

It has to be a bug and that is how I am marking this post. You cannot have a 3-row dataset and minSpareRows: 1, and get 5 rows at the start. Thank you very much for your effort to investigate it.

Issue reported at https://github.com/handsontable/handsontable/issues/4195

I am trying achieve the same thing as the original poster of this bug. Is there another way to set a default cell value without using dataSchema since it’s full of bugs and doesn’t work? Some of these bugs really need to be fixed in order to even use handsontable for complex projects.

Hi @pwong

Can you share your requirements? If you’d like to add the value after table is loaded and you have some empty cells you can run the getDataAtCell and search for an empty string, when you use minSpareRows or when you allow to use a fillHandle to populate data. it all has a pretty different case.

Generally, you can use setDataAtCell, loadData or a custom renderer - it all depends on your requirements.

My requirement is simple. I have a bunch of dynamically generated tables. Every time a new row is added using minSpareRows, one cell has to be set to a specific value. I tried using afterCreateRows to set the value but the table goes into an infinite loop; adding new row after new row.

Hm… that is pretty odd. Actually, I think that the afterCreateRow is a perfect callback for this situation.

I have made a simple demo to show how it works http://jsfiddle.net/7w0rb2be/
Maybe in your example, one callback calls another and they go into an infinite loop?

Your example doesn’t use minSpareRows. I don’t want buttons everywhere to add a new row since I have a bunch of table instances. It also defeats the whole point of minSpareRows. Add the the minSpareRows: 1 declaration to your example and you will see the infinite loop. Is there any column property to set a default value?

You’re right. The demo goes into the Uncaught RangeError: Maximum call stack size exceeded when we add minSpareRows.

I have tried the afterChange + afterCreateRow with the alter method and this actually is returning calls between themselves, but… there’s a workaround for it.

Please check this demo http://jsfiddle.net/7w0rb2be/1/
Normally the afterChange hook that pushes a new row via checking if the last row is empty would push a new row and fill it with data, and the process will go on till forever, but if we restrict that the code shouldn’t execute if the value is actually the one that we’re using as a placeholder then the wheel stops and code works as expected. The only question left is: Can user actually leave the placeholder as it is or he has to change it?

Perfect! This will work for now because the user can’t edit the placeholder. It’s actually a hidden column for sorting the data. Thank you for your help!

Great. Thank you for an update.

This is still not fixed in the last version. Changing value in cell causes adding a new spare row which is not needed

https://jsfiddle.net/8rn5mfpL/

Hi @dan

@latest redirects to the 7.4.2 (latest not beta version).
If you’d like to test beta2 that will be released soon you can use those resources

https://cdn.jsdelivr.net/gh/handsontable/handsontable@feb34394d29b65837cb8f0e32b187c41de68434f/dist/handsontable.full.min.js
https://cdn.jsdelivr.net/gh/handsontable/handsontable@feb34394d29b65837cb8f0e32b187c41de68434f/dist/handsontable.full.min.css

Demo updated https://jsfiddle.net/AMBudnik/jfb4dyw2/1/

With age = 0 it looks good, but not when I change it to checkbox

https://jsfiddle.net/juoxLtmp/

try to just check/uncheck first row

You’re right. The schema

dataSchema: {name: "", age: true, hobbies: []}

breaks the rendering and adds a new row on check/uncheck. I can see that this issue has been reported some time ago here https://github.com/handsontable/handsontable/issues/5069 and I do not see this issue in the scope of Handsontable 8.0.0.
However, I will let you know as soon as we get it solved.