Hey ScottE,
Adding custom datatips (tooltips) directly to UITable components for individual cells is not natively supported in the same way as it is for plots. However, you can achieve a similar effect by using uitable properties and callbacks.
Here’s an approach to simulate datatips for a UITable in App Designer by using the CellSelectionCallback and TooltipString properties:
You can follow below steps to acheive the same:
1. Add a UITable to Your App:
Drag a UITable component onto your app from the Component Library.
2. Define Your Data and Units:
Store the information (like units) in a separate structure or cell array.
3. Implement the CellSelectionCallback:
Use the `CellSelectionCallback` to update the tooltip based on the selected cell.
Here’s an example to illustrate how you can implement this:
Here is the complete example:
classdef MyApp < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
UITable matlab.ui.control.Table
end
properties (Access = private)
Units % Cell array to store units or additional info
end
methods (Access = private)
% Function to initialize the table and units
function initializeTable(app)
% Example data for the table
data = {
'Item1', 10, 20.5;
'Item2', 15, 30.75;
'Item3', 20, 40.25
};
% Set the data to the UITable
app.UITable.Data = data;
% Define the units or additional information
app.Units = {
'Item Name', 'Count (units)', 'Value (USD)'
};
end
% Cell selection callback function
function UITableCellSelection(app, event)
% Get the indices of the selected cell
indices = event.Indices;
if ~isempty(indices)
% Get the column index of the selected cell
colIndex = indices(2);
% Update the tooltip based on the selected column
tooltipText = app.Units{colIndex};
app.UITable.Tooltip = tooltipText;
else
% Clear the tooltip if no cell is selected
app.UITable.Tooltip = '';
end