I have an existing dataset created from
resultDS = databaseManager.getDatasetByQuery()
The below code does not add a row at the end of the dataset
resultDS.addRow(resultDS.getMaxRowIndex(), new Array(“11”, 11111111));
The below code does not add a row at the beginning of the dataset
resultDS.addRow(1, new Array(“11”, 11111111));
And if you try
resultDS.addRow(new Array("11", 11111111));
As far as I see the tooltip suggests you just provide the values, not the position in the dataset (Servoy 3.1).
The example seems to work. It adds the row at the end.
But this syntax does not work
dataset.addRow([number index], Object array)
Specifying index does not work
At least in 3.1 there is no hint that this should work!?
I can reproduce this in 3.5 where according to the tooltip this should work.
var ds = databaseManager.convertToDataSet([]);
ds.addRow(["value 1"]);
ds.addRow(["value 2"]);
ds.addRow(1, ["inserted value"]); // Insert value into row 1
application.output(ds.getValue(1,1));
--> value 1
Servoy Developer
Version 3.5 rc4-build 509
Java version 1.5.0_07-87 (Mac OS X)
Then we have a problem, because the tooltip in 3.1 says addRow(array). So if they changed it to addRow(index, array), it’d break “old” functionality. So if it is changed, its should be changed to addRow(array, index).
I don’t think it will break old code.
When you overload a function you can pass different types of values to the function and the language will figure out which instance of the function to use.
Since an Integer is not an Object Array it will use the correct function.
What this new function does however is diverting from the coding style that is used throughout Servoy.
OK. I tried with 3.5 and can confirm that something like
addRow(1, new Array('', null))
does not work.
Should something like the following work:
dataset.addRow(4, 'string_value_to_insert')
where 4 is the index to add to an existing 3 row dataset (used for testing in lieu of getMaxRowIndex()).
I am having trouble getting the above going in 3.5 and wondering if I need to pass an array instead.