How to scroll a sorted UITable?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I need to programmaticaly scroll to a selected line of a UITable in an app, and everything works perfectly until I use the "ColumnSortable" option of the UITable: The scroll function goes to the original location of the line, and not at it sorted location. Do you have any workaround for such cases?
1 commentaire
dpb
le 10 Juin 2022
Not directly, but I'd guess you'd probably have to rewrite the .Data property with the data in the sorted order and turn of 'Sort' flag.
Réponses (1)
Shivam
le 5 Jan 2024
Hi,
From the provided details, I understand that after using the 'ColumnSortable' property of the uitable, the scroll function goes to the original row, not the sorted row of the uitable.
It is important to note that when you set the 'ColumnSortable' property of a uitable in MATLAB to true, you can click on the column headers to sort the table by that column. However, this sorting is only a visual change and does not modify the underlying data array in the 'Data' property of the uitable. That is why the 'scroll' function does not reach the sorted location.
To overcome this issue, you can sort the original matrix and set the Data property of uitable to the sorted matrix.
You can follow the below workaround to sort the original matrix and set the Data property:
% Create data for uitable
mat = randi(30,10,2)
% Create uitable
fig = uifigure;
uit = uitable(fig,"Data",mat);
col = ["A","B"];
uit.ColumnName = col
% Sort original matrix using column 1 and set uit.Data to sorted matrix
sortedMat = sortrows(mat, 1)
uit.Data = sortedMat
You can now use the 'scroll' function to navigate to the correct sorted location.
Please refer to the following documentation to know more about 'uitable', 'scroll' and 'sortrows' functions:
- https://www.mathworks.com/help/releases/R2023b/matlab/ref/uitable.html
- https://www.mathworks.com/help/releases/R2023b/matlab/ref/matlab.ui.container.tree.scroll.html
- https://www.mathworks.com/help/releases/R2023b/matlab/ref/double.sortrows.html
I hope it helps in resolving the issue.
Thanks
0 commentaires
Voir également
Catégories
En savoir plus sur Whos dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!