0
votes

I have a UiApp, that has a FlexTable, each row represents a locations. These locations are marked by checkboxes, the users seletc them and when they execute the save function I'd like to update the table so that only the selected rows remain.

...
var checkbox_sorszam = []
var rows_to_del = []

  for(var i = 0; i < locations_data.length; i++)
  {
    if(e.parameter['checkboxischecked'+i] == 'true')
    {
      location_list.push(e.parameter['checkbox_value_'+i]);
      checkbox_sorszam.push(i)
    }
    if(e.parameter['checkboxischecked'+i] == 'false')
    {
      rows_to_del.push(i)
    }   
  }

This way I have the index of rows that need to be deleted

for (var d=0;d<rows_to_del.length;++d)
  {
    Logger.log(rows_to_del[d])
    tarhely_table.removeRow(rows_to_del[d])        
  }

I get an 'Invalid value: row' error. I tried parseInt(rows_to_del[d]), same results. I prefer not creating a new table but to delete rows which the users did't select.

1
what do you have in Logger.log(rows_to_del[d]) ? - Serge insas
[1.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0] the row indexes of rows that are not selected, (1st row, 2-3rd slected with indexes:0, 2, 3) - bazari
So I think in theory it should work as the table rows are also 0 indexed.There are 13 rows, 0-12 is in rows_to_del[] if all is selected. Of course I tried tarhely_table.removeRow(1) for example. Same error. - bazari
thanks for the info. It seems indeed it should be valid... I'll try this on a test and let you know if I find something later. no time right now ;-/ - Serge insas
Thanks Serge, it's not too important, but would be helpful if it worked. - bazari

1 Answers

1
votes

Consider deleting the rows in reverse.

Let's say your table initially has 3 rows in it:

0: red
1: green
2: blue

User selects row 1, so you plan on deleting rows 0 and 2.

First time though the loop, you delete row 0. Now your table is:

0: green
1: blue

Second time through the loop, you delete row 2

There is no row 2....

Starting over, let's say user selects row 2: blue, so you plan on deleting 0 and 1.

First time through the loop, you delete row 0, now your table is:

0: green
1: blue

Second time through the loop, you delete row 1, now your table is:

0: green

User is confused.