Basically, I think I Need to change the way of comparing/sorting values in each column... Instead of only sorting after the first numeric value, it should take the whole number into consideration... Btw the underlying datatype of the column data is double. If I look for methods(jtable) I get a list with all possible methods. Still I cannot figure out how to adjust the sorting order (perhaps sth. with Comparator...)
Sort Numbers correctly in an uitable
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hey guys,
I want to sort the numbers this way (e.g. 145 129 90 2 -1) inside my uitable htable. Instead the following code sorts the numbers in that way (-1 129 145 2 90). It´s obvious that the program is just sorting after the first numeric value. Has someone got a clue about how to sort these numbers right? Below you will find the current code, which implements the sorting (Credits to Yair Altman).
Many thanks in advance!
% Display the uitable and get its underlying Java object handle
jscrollpane = findjobj(hTable);
jtable = jscrollpane.getViewport.getView;
% Now turn the JIDE sorting on
jtable.setSortable(true);
jtable.setAutoResort(true);
jtable.setMultiColumnSortable(true);
jtable.setPreserveSelectionsAfterSorting(true);
Réponses (1)
Stephen23
le 4 Juin 2018
Modifié(e) : Stephen23
le 4 Juin 2018
I am sure that you could find some Java add-on that provides this functionality, but if you want to sort strings with numeric values then basically you will need to get the table values, convert to numeric (if required), sort, and then apply that sort order to the contents of the table.
If the data are a cell array of strings (char vectors) then one way of doing this would be to download my FEX submission natsortrows:
Voir également
Catégories
En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!