How to filter on uitable popup menu?
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Arvind Murali
am 6 Mär. 2017
Beantwortet: Kevin Gleason
am 14 Mär. 2017
I am working on a uitable with 2 columns. In column A, I have a list of standard names used within the program. In column B, the columnformat popup is being fed by the list of names obtained from the users data file. This popup has about 500 names. Like this:
With around 500 options, this is a pain to manually select for each option. Is there a better way to do this or can I implement a filter of some sort? I was thinking in lines of using a keypressfcn maybe but did not have a good idea of how to implement this. Also, if not for a uitable, would this be easier as a listbox or combobox or something? Also since I'm going to have to be able to use it in multiple computers, I cant do java based technique with findobj etc. Any ideas is appreciated. Thank you.
0 Kommentare
Akzeptierte Antwort
Kevin Gleason
am 14 Mär. 2017
Hello Arvind,
There is no simple way to accomplish this, but from a high level, here is my suggestion:
1. Any of the drop down items that require filtering, add an option to the list called 'Choose'.
2. In the "CellEditCallback", if the 'Choose' option was ever selected, launch a chooser window.
3. This chooser window (up to you), could have a dropdown, text edit, and OK button.
3.5 Pass all the menu options to the chooser window drop down. You can use the text edit to filter. Start typing, modify the edit text callback to filter out elements of the dropdown if they share a common stem. Then finally select an item from the drop down and click OK. Close the chooser window once you click 'OK'.
4. Transmit the data back to your original UI, and set the Table value to your filtered selection.
The following code works in R2016b and after, and can be used as an example of the above workflow:
% Create sample table
fmt = {'Choose' 'B' 'C' 'D'};
t = uitable('Data',{'A';'A'},...
'ColumnEditable',true(1,2),...
'ColumnFormat',{fmt});
% Set callback for CellEditCallback, triggered on menu item changed
t.CellEditCallback = @EditCallback;
function EditCallback(tHandle, event)
if (event.EditData == 'Choose')
% Create a chooser window
chooseFig = figure;
b = uicontrol(chooseFig, 'Style','pushbutton',...
'String', 'Click Me',...
'Callback',@pushbutton_callback);
% Launch new Figure
% event.Indices is the Row/Col to edit
% event.NewData has the new data
disp('Getting Val from Figure');
% On Figure 'OK' button, set the row/col
waitfor(chooseFig);
disp('Wait Done! Setting Value');
end
function pushbutton_callback(hChooser,~)
% Get the data out of hChooser
idx = event.Indices;
tHandle.Data(idx(1), idx(2)) = {'NewData'};
% Close the popup window
delete(hChooser.Parent);
end
end
This will launch a new figure window when you select 'Choose' and once you click the OK button, it will return and restore the value 'New Value' to the original UI Table
Hope this helps!
Best, Kevin
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!