uitable does not update values (in its own callback?)?

69 views (last 30 days)
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
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

Sign in to comment.

Answers (7)

Craig DeAlmeida
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
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
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.

Sign in to comment.


Steve Page
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
Henning
Henning on 17 Jul 2019
Thanks for the effort and info!
I must admit, for me this is disappointing, I was so looking forward to use the table data type as data for the uitable table GUI element (sounds like the two should go together). No conversions, no checks, just using it.
In combination with other problems I keep experiencing with uitable (weird resizing, tremendously slow rendering, ...), it makes it tough to use this element.
Well, I guess I keep my fingers crossed, that the uitable will receive more love (and support) in future releases.
Happy programming
Henning
Ismaeel
Ismaeel on 20 Jan 2022
Where is the attachement you talked about?

Sign in to comment.


Ann Marie Ward
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

Farsad Zamani
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.

Steve Page
Steve Page on 11 Oct 2019
This problem has been fixed in R2019b

Kyle Owen
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
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

Sign in to comment.


Hamza Zaki
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??

Categories

Find more on Interactive Control and Callbacks 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!