MATLAB Answers

How can I have 'dropdown' in every cell of a table in App Designer ?

161 views (last 30 days)
The requirement is having a drop down menu embedded in each row of the table to select from multiple options. We know that we can use checkboxes in the table but that will expand the table vertically which would result in lots of scrolling for the user. We also know that UITable in App designer does not have any children.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 19 Mar 2019
Yes, UITable is a leaf component and does not have any child. The 'Data' property is the only property to set tabular data in UITable. Currently drop down menus in UITable is supported using the 'ColumnFormat' property.
In the App Designer startup function:
app.UITable.Data = {'female';'male';'male'}; % have 3 rows of gender information.
app.UITable.ColumnFormat = {{'male', 'female'}}; % have option cell array within ColumnFormat property to indicate the 1st column is using dropdown menus.
app.UITable.ColumnEditable = true;
More information can be found in UITable 'ColumnFormat' property in MATLAB Documentation
  1 Comment
Rodriguez Pham
Rodriguez Pham on 8 Jul 2019
Is there a way to make it so the drop down is different for each cell?
In the linked provided it shows that there is a group 1 and group 2 for the 4th column.
For example can the 2nd row on the 4th column have group 1,2 3 while the rest have group 1 and group 2

Sign in to comment.

More Answers (1)

Melinda Toth-Zubairi
Melinda Toth-Zubairi on 25 Mar 2019
Starting in R2018a, you can display table array data in a Table UI component. To display a drop-down list, you can convert a cell array of character vectors to a categorical array using the categorical function:
uf = uifigure('Position',[100 100 752 250]);
uit = uitable('Parent',uf,'Position',[25 50 700 200]);
load patients
t = table(LastName,Age,Weight,Height,Smoker,SelfAssessedHealthStatus);
t.SelfAssessedHealthStatus = categorical(t.SelfAssessedHealthStatus,{'Poor','Fair','Good','Excellent'}, ...
uit.Data = t;
uit.ColumnEditable = [false false true true true true];
Ordinal categorical arrays always have protected categories. Or you can create a nonordinal categorical array that is protected using the 'Protected',true name-value pair argument. If the categorical array is not protected, users can add new categories in the running app by typing in the cell. You can try this by eliminating the 'Ordinal',true in the above code.
For more information, see the following MATLAB documentation.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!