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
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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);
Respuestas (1)
Stephen23
el 4 de Jun. de 2018
Editada: Stephen23
el 4 de Jun. de 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:
Ver también
Categorías
Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!