Delete row in a user-sorted UItable throws error

1 回表示 (過去 30 日間)
Jan Kudlacek
Jan Kudlacek 2022 年 1 月 11 日
編集済み: Jan Kudlacek 2022 年 1 月 11 日
Dear colleagues
I have a UItable with sortable columns. Users can delete rows which is implemented by deleting a row from the Data property. This seems to replace also the read-only property DisplayData which is correct. However, if the user sorts the table by clicking the sort icon prior to the row deletion, the DisplayData cannot be accessed afterwards. Am I doing something wrong? Try the following code:
function uitableRowDeletion
% Situation A:
% 1. Run the script
% 2. Press delete
% 3. It deletes second row, as it should. Everything OK.
%
% Situation B:
% 1. Run the script
% 2. Sort the data by clicking on the show-up button in the upper right corner of the uitable
% 3. Press delete
% 4. Accessing DisplayData property now results in error
h = findall(0,'type','figure'); close(h); % Close all uifigures
clear;
A = [1 3 2]';
t = table(A);
f = uifigure('WindowKeyPressFcn', @cbKey);
uit = uitable(f, 'Data', t, 'ColumnSortable', true);
% Nested callback function, deletes hard-coded second row
function cbKey(~, evt)
if strcmp(evt.Key, 'delete')
uit.Data(2, :) = [];
disp(uit.DisplayData)
end
end
end
Thank you for any ideas.
Jan Kudláček
  2 件のコメント
Jan
Jan 2022 年 1 月 11 日
Please mention the Matlab version you are using and post the error message you get.
Jan Kudlacek
Jan Kudlacek 2022 年 1 月 11 日
R2019b
Error using matlab.ui.internal.controller.uitable.WebMWTableController.createDisplayData (line 607)
Row index exceeds table dimensions.
Error in uitableRowDeletion/cbKey (line 25)
disp(uit.DisplayData)
Error using matlab.ui.internal.controller.FigureController/handleEvent (line 362)
Error while evaluating Figure WindowKeyPressFcn.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by