Apologize in advance for a lengthy message.
I am trying to use JIDE uitable filtering code from:
http://coderazzi.net/tablefilter/matlabjava.pdf
Here is that code:
% An example for a simple (???) JIDE filter
data = num2cell([magic(3);magic(3)]);
jtable = com.jidesoft.grid.SortableTable(data,{'a','b','c'});
tableHeader = com.jidesoft.grid.AutoFilterTableHeader(jtable);
tableHeader.setAutoFilterEnabled(true)
tableHeader.setShowFilterName(true)
tableHeader.setShowFilterIcon(true)
jtable.setTableHeader(tableHeader)
installer = com.jidesoft.grid.TableHeaderPopupMenuInstaller(jtable);
pmCustomizer1=com.jidesoft.grid.AutoResizePopupMenuCustomizer;
installer.addTableHeaderPopupMenuCustomizer(pmCustomizer1);
pmCustomizer2=com.jidesoft.grid.TableColumnChooserPopupMenuCustomizer;
installer.addTableHeaderPopupMenuCustomizer(pmCustomizer2);
jScrollPane = javax.swing.JScrollPane(jtable);
[hjtable,hjcontainer]=javacomponent(jScrollPane,[20,20,200,150],gcf);
Once sorted, or filtered, how does one determine the selected row(s) with respect to the original table?
I have used GUIDE to build the uitable and hence, not creating the uitable in the Matlab code:
HERE IS MY CODE:
data = num2cell([magic(3);magic(3)]);
%Load Data to UITable
set(handles.uitableData,'Data',data);
% Now turn the JIDE SORTING on
jScroll = findjobj(handles.uitableData);
jtable = jScroll.getViewport.getView;
jtable.setSortable(true);
jtable.setAutoResort(true);
jtable.setMultiColumnSortable(true);
jtable.setPreserveSelectionsAfterSorting(true);
% Turn FILTERING On
tableHeader = com.jidesoft.grid.AutoFilterTableHeader(jtable);
tableHeader.setAutoFilterEnabled(true)
tableHeader.setShowFilterName(true)
tableHeader.setShowFilterIcon(true)
jtable.setTableHeader(tableHeader)
installer = com.jidesoft.grid.TableHeaderPopupMenuInstaller(jtable);
pmCustomizer1=com.jidesoft.grid.AutoResizePopupMenuCustomizer;
installer.addTableHeaderPopupMenuCustomizer(pmCustomizer1);
pmCustomizer2=com.jidesoft.grid.TableColumnChooserPopupMenuCustomizer;
installer.addTableHeaderPopupMenuCustomizer(pmCustomizer2);
jScrollPane = javax.swing.JScrollPane(jtable);
[hjtable,hjcontainer]=javacomponent(jScrollPane,getpixelposition(handles.uitableData,true),gcf);
If the user selects row(s) or cell(s), I receive the selection through uitableData_CellSelectionCallback function. However, it is returning the selection w.r.t. the sorted uitable.
I tried the following code but it does not work:
% --- Executes when selected cell(s) is changed in uitableData.
function uitableData_CellSelectionCallback(hObject, eventdata, handles)
selection_raw = eventdata.Indices(:,1);
data_temp=get(handles.uitableData,'Data');
selection = data_temp(selection_raw,1); % My Data Table has Row IDs in the First Column
I see the following comments in
http://coderazzi.net/tablefilter/matlabjava.pdf:
To retrieve the actual data in a filtered table, use the table's RowSorter object. For
example, the following code returns the selected (filtered) row's data upon selection a
specific table cell with the mouse:
set(jtable.getSelectionModel, 'ValueChangedCallback', ...
{@selectionCallbackFcn,jtable});
function selectionCallbackFcn(jModel, jEventData, jtable)
rowIdx = get(jModel,'LeadSelectionIndex');
try
rowIdx = jtable.getRowSorter.convertRowIndexToModel(rowIdx);
catch
% never mind: no filtering is used so stay with existing rowIdx
end
% Now do something useful with the selected row's data…
data = jtable.getModel.getValueAt(rowIdx,1); % column #2
% Alternate way to get the selected row's data…
data = jtable.getActualRowAt(rowIdx);
% ...
end % selectionCallbackFcn
But this is not working for me. Also, I am not able to access the jtable in uitableData_CellSelectionCallback function.
I am not good with JAVA and/or MATLAB uitables.
Any help you can provide is greatly appreciated.
Best Regards,
Ratna