InsertRow to a particular row

Is there anyway I can insert row to a particular row? Means, for example, I have:
Item A
Item B
Item C

Item D

Now I have a new Item E that I want to be in row 2,

Item A

Item E

Item B

Item C

Item D

Do InsertRow has a parameter to do that?

There is no way to do what you want in a simple insertRow call. You need to maintain your data set in a table, insert the new row in the appropriate place in the table and then drop the data in the tableView and then load your table into the tableView again. Since this happens pretty quickly it is usually ok visually. In other words you only see a brief flicker and the new row gets shown in the inserted position.

@primozcerar’s upcoming grid component does allow in place row inserts and is so much more user friendly. Once it is released I can imagine many of you using it for things like this. All the best.

I end up dig into tableView widget, and able to do it.

This is the brief logic:

  1. Insert a row to your table, like: tableView:insertRow{…}
  2. go into tableView._view._rows, you see all your rows data, the newly added row should be the last entry.
  3. ._rows is an index table, so I did a table.insert(tableView._view._rows, 3, last_row), assuming I am insert to 3rd row.
  4. clear the last ghost table, set it to nil (tableView._view.rows[#tableView._view.rows] = nil
  5. loop through ._rows, modify every row after 3, by adding the row.y by 1 row height.
  6. tableView:reloadData()
  7. Sleep time.

There is no way to do what you want in a simple insertRow call. You need to maintain your data set in a table, insert the new row in the appropriate place in the table and then drop the data in the tableView and then load your table into the tableView again. Since this happens pretty quickly it is usually ok visually. In other words you only see a brief flicker and the new row gets shown in the inserted position.

@primozcerar’s upcoming grid component does allow in place row inserts and is so much more user friendly. Once it is released I can imagine many of you using it for things like this. All the best.

I end up dig into tableView widget, and able to do it.

This is the brief logic:

  1. Insert a row to your table, like: tableView:insertRow{…}
  2. go into tableView._view._rows, you see all your rows data, the newly added row should be the last entry.
  3. ._rows is an index table, so I did a table.insert(tableView._view._rows, 3, last_row), assuming I am insert to 3rd row.
  4. clear the last ghost table, set it to nil (tableView._view.rows[#tableView._view.rows] = nil
  5. loop through ._rows, modify every row after 3, by adding the row.y by 1 row height.
  6. tableView:reloadData()
  7. Sleep time.