uitable does not update values (in its own callback?)?
25 views (last 30 days)
Show older comments
Hello,
I have a problem with the uitable not updating its shown values (tested with appdesigner app, R2019a).
There is a callback function UITableCellEdit that also sets a value in a different column. As a simple example, if a value is edited (the callback is fired), the value in column 1, row 3 is set to the same value.
The problem: after the callback is finished, the shown value is not updated (i.e. the value in column1, row 3). If a breakpoint is used and the data property of the table is inspected (app.UITable.Data), the correct value is displayed for the data. When any value is changed via a different callback, e.g. a spinner or button pushed callback, the whole table is updated and the correct value is shown, even the one that was previously shown incorrectly and even though it was not explicitly set. See also the screenshots, at the breakpoint with incorrect shown value (marked red) and after finishing callback of the button.
So my question is, is this a bug? Or am I doing something wrong? Any ideas for a workaround (except not updating other values with the cell edited callback?)
I tried also placing drawnow commands at various places, but to no avail.
Here is the code for the table callback and for the button:
% Cell edit callback: UITable
function UITableCellEdit(app, event)
indices = event.Indices;
NewData = event.NewData;
% drawnow;
% drawnow("nocallbacks");
app.UITable.Data.TmpData1(3) = NewData;
% drawnow;
% drawnow("nocallbacks");
end
% Button pushed function: Button2_2
function Button2_2Pushed(app, event)
NewValue = randi(10,1);
app.UITable.Data.TmpData1(2) = NewValue;
end
Before breakpoint, incorrect value shown (last edited value is column 3, row 3, value: 1111)
After breakpoint, correct value shown, even though not explicitly set
1 Comment
Steve Page
on 30 May 2019
Hi,
I am experiencing exactly the same problem. I have noticed that when I sort a column in the uitable, after I have updated the table in the CellEdit callback, it makes the correct data appear. I am still investigating and I will also raise a service request as it looks like a bug to me. Will keep you posted.
Regards
Steve
Answers (8)
Craig DeAlmeida
on 30 May 2019
Same issue here, seems like a bug (thanks, Steve, for raising a service request), for me I had built up a table in a variable called ToDisplay within the CellEdit callback and at the end assigned it to the Data property:
% ... near end of CellEdit callback for uitable called ThisTable
% Assign table variable ToDisplay to Data property of uitable
ThisTable.Data = ToDisplay;
In certain situations this caused behavior like yours.
However, I just cam up with a workaround that seems to work--clear out the Data property of the table using an empty table then put the entire table back in the Data property.
% ... near end of CellEdit callback for uitable called ThisTable
% Clear out existing data
ThisTable.Data = table.empty;
% Assign table variable ToDisplay to Data property of uitable
ThisTable.Data = ToDisplay;
No drawnow statements needed--the table flickers briefly but then shows the right data the first time.
2 Comments
Craig DeAlmeida
on 30 May 2019
Well...it almost works...the row name in my table is not updated but the table contents are. Weird.
Steve Page
on 31 May 2019
Hi - I tried your workaround but whenever I assign table.empty to my uitable.Data property I get an exception: -
Variable index exceeds table dimensions.
This problem occurs in the CellEditCalbback and the DisplayDataChangedFcn but not when I do the assignment in startupfcn (which I did just to see what happens).
I haven't had any response from TMW to my Service Request but hopefully will get at least an acknowledgement today. Will keep you posted.
Steve Page
on 1 Jun 2019
Edited: Laura Hild
on 3 Jun 2019
Hi All,
I have received the following very helpful response from MathWorks Technical Support: -
Here are some potential workarounds that may be suitable for you:
1) If being able to sort the columns is not essential then you could use a cell array instead of a table for the 'Data' property of the uitable ('ProjectTable'). This behaves as you would expect when selecting the selection boxes. However you will no longer be able to sort columns with this option. I have attached an example with this modification called ExampleCellArray. Please take a look at it.
2) If instead clicking right in the center of the selection boxes is not a hard requirement, you could use the CellSelectionCallback instead of the CellEditCallback. The contents of the callback would be nearly identical. I have attached an example with this modification called ExampleCellSelection. Please take a look at it. Note that I am tracking the sorted data in a property called 'SortedTable' to preserve the current sorted order in this case.
I believe these approaches should help you avoid this issue.
--------------------------------------------------------------------
I have implemented the ExampleCellSelection solution in my own app (where table column sorting is important) and it worked fine. Note: all columns are set with the 'Editable' property = false (which didn't stop the Select column displaying a tick when selected!)
I have been unable to attach MW Tech Support ExampleCellArray.mlapp and ExampleCellSelection.mlapp files because this page does not support attachment of files with extension of .mlapp!!! If you want them then please email me at steve.page@val-cloud.com and I will send them to you.
I hope this helps to resolve your issues.
Best wishes
Steve
2 Comments
Ann Marie Ward
on 30 Sep 2019
I have the same problem, and I think this is a bug that should be fixed.
My workaround is to add a button labeled “Update Table”. For some reason displaying the data with the callback on the button works. I have the same code in the DisplayDataChangedFcn callback on the UITable, but it doesn’t update the data on the screen.
It’s a little lame and gives my app a Web 1.0 look and feel but at least it’s useable.
Ann Marie
0 Comments
Farsad Zamani
on 11 Oct 2019
Hello,
I tried the following workaround:
app.UITable.Data=[];
set(app.UITable,'Data',tdata);
drawnow;
the table is refreshed but very slowly.
0 Comments
Kyle Owen
on 18 Aug 2020
I still observed a similar issue in 2020a. The workaround of first clearing the table using:
app.UITable.Data= [];
Then defining it as before seems to work.
1 Comment
Richard Genik
on 6 Oct 2020
I still observe similar behavior in R2020a. There is no reference to a bug fix I found in the R2020b release notes.
I have an app that calls another app to load enumerated column data from a .csv file into a cell array, filter it, and produce a table in the child GUI that allows for manual selection of rows. The selected rows are then to be returned to the parent (CallingApp). Several designs of the app were implemented and the parent table display was never updated. I subsequently found the thread documenting this bug. I will skip commentary on the number of wasted hours my team spent dealing with this issue and provide some constructive information…
In the latest implementation, we created a set method in the parent application to fill the table in the CallingApp after completed filtering and user selection of rows.
This implementation worked around the Matlab bug (this is a method in the CallingApp):
function results = setParentTable(app,InputTable)
app.ParentTable.ColumnName = app.ColumnNames;
app.ParentTable.Data = InputTable.Data;
results = 1; % used for setting breakpoint
end
This was the original attempt that did not update the table in the parent Window (it should have):
function results = setParentTable(app,InputTable)
app.ParentTable = InputTable;
results = 1; % used for setting breakpoint
end
We additionally tried the work-arounds cited above, and note that this attempt fails to update the parent table display, AND erases the input table data:
function results = setParentTable(app,InputTable)
app.ParentTable = InputTable;
app.ParentTable.Data = [];
app.ParentTable.Data = InputTable.Data;
results = 1; % used for setting breakpoint
end
The erasure of the input data in this code points to an issue in the copy method of the uitable class. Likely a typo that overwrites the output to the input pointers, but that is speculation…
So it seems the workaround is to set the properties individually and not rely on the simpler object copy.
Sincerely,
Rich
Hamza Zaki
on 31 Mar 2022
I am trying a code
A = randi(50,N,14);
A(1:N,4:13)=logical(N)
I want that all Bool should appear as check box what shall I do??
0 Comments
Yanjie
on 17 Jun 2024
I am using R2023B, facing same problem, want update the specific table value based on the CSV file by button click call back, does not work, Need to re-make the whole table to let it update...
S.uit1.Data= CSV_voltage; %%this does not work (only change date of this table)
S.uit1= uitable(S.fh,"Position",[550 275 450 80],...
"Data",CSV_voltage, "ColumnWidth","1x"); %% this one works, re-make the whole table. new date is there.
0 Comments
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!