Add a new row between old table rows in Matlab appdesigner

1000 views Asked by At

After some research, I still can't find the solution for my problem. I have a table that it's filled with info from user, when a button is pushed. The idea is that once new information is inserted and the "add" button pushed, a new row is created on the table. For instance:

  1. Start with a table of 5 rows
  2. The user places the cursor at the third row (selected)
  3. The user clicks on add new row button
  4. A new row is added at row #3 and the old third row is now row #4

Does any of you have a suggestion?

1

There are 1 answers

0
BoilermakerRV On

Here's one approach. Create a property in your UIFigure called CurrentRow.

properties (Access = private)
    CurrentRow % Last row selected in UITable
end

Whenever the user clicks on a cell in the table, the UITableCellSelection event is fired and you can set the CurrentRow property to be the selected row.

% Cell selection callback: UITable
function UITableCellSelection(app, event)
    app.CurrentRow = event.Indices(1);
end

Next the user clicks the "new row button" and we use the ButtonPushed event to insert the new row.

% Button pushed function: Button
function ButtonPushed(app, event)
    insertedRow = [1 2 3 4];
    temp = [app.UITable.Data(1:app.CurrentRow-1,:);insertedRow;app.UITable.Data(app.CurrentRow:end,:)];
    app.UITable.Data = temp;
end

Obviously, you will get the new row values from some other control on your form, whereas I've just assigned hard-coded values as an example.