<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Uitable sorting	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/uitable-sorting/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/uitable-sorting?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=uitable-sorting</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Tue, 14 Aug 2018 01:04:40 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/uitable-sorting#comment-435471</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Tue, 14 Aug 2018 01:04:40 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2391#comment-435471</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/uitable-sorting#comment-435454&quot;&gt;Dan&lt;/a&gt;.

@Dan - uifigures are based on HTML and JavaScript, they are basically nothing more than a webpage displayed within a browser window. In comparison, legacy figures are based on Java desktop windows. So any customization that works on the Java-based figures and relies on Java (including uitable customizations) will never work in uifigures, and you cannot get the Java handle of uifigure components because they&#039;re not based on Java.

For details on uifigure customizations, refer to the list of &lt;a href=&quot;http://undocumentedmatlab.com/blog/tag/uifigure&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;posts that have the uifigure tag&lt;/a&gt;.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/uitable-sorting#comment-435454">Dan</a>.</p>
<p>@Dan &#8211; uifigures are based on HTML and JavaScript, they are basically nothing more than a webpage displayed within a browser window. In comparison, legacy figures are based on Java desktop windows. So any customization that works on the Java-based figures and relies on Java (including uitable customizations) will never work in uifigures, and you cannot get the Java handle of uifigure components because they&#8217;re not based on Java.</p>
<p>For details on uifigure customizations, refer to the list of <a href="http://undocumentedmatlab.com/blog/tag/uifigure" target="_blank" rel="nofollow">posts that have the uifigure tag</a>.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Dan		</title>
		<link>https://undocumentedmatlab.com/articles/uitable-sorting#comment-435454</link>

		<dc:creator><![CDATA[Dan]]></dc:creator>
		<pubDate>Mon, 13 Aug 2018 21:46:16 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2391#comment-435454</guid>

					<description><![CDATA[Thank you so much. This works well for UITables embedded in a traditional figure but I&#039;m having issues getting findjobj to work when the UITable is embedded in a UIFigure, it just returns an empty array. (I have an application build in App Designer.) Is there another way to get the Java handle to the UITable when it&#039;s in a UIFigure?

Thanks,
Dan]]></description>
			<content:encoded><![CDATA[<p>Thank you so much. This works well for UITables embedded in a traditional figure but I&#8217;m having issues getting findjobj to work when the UITable is embedded in a UIFigure, it just returns an empty array. (I have an application build in App Designer.) Is there another way to get the Java handle to the UITable when it&#8217;s in a UIFigure?</p>
<p>Thanks,<br />
Dan</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/uitable-sorting#comment-413947</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Sun, 24 Sep 2017 07:33:54 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2391#comment-413947</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/uitable-sorting#comment-413871&quot;&gt;Meade Spratley&lt;/a&gt;.

@Meade - I do not have an immediate answer, but it&#039;s quite possible that a solution can be found. If you&#039;d like me to investigate this (for a consulting fee) then email me.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/uitable-sorting#comment-413871">Meade Spratley</a>.</p>
<p>@Meade &#8211; I do not have an immediate answer, but it&#8217;s quite possible that a solution can be found. If you&#8217;d like me to investigate this (for a consulting fee) then email me.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Meade Spratley		</title>
		<link>https://undocumentedmatlab.com/articles/uitable-sorting#comment-413871</link>

		<dc:creator><![CDATA[Meade Spratley]]></dc:creator>
		<pubDate>Thu, 21 Sep 2017 22:17:39 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2391#comment-413871</guid>

					<description><![CDATA[Hi Yair,

I think I have a new problem, maybe you haven&#039;t seen!

I&#039;m using a uitable to make an interactive name builder.  Basically, I&#039;m creating a table with dynamic column names.  The user can then change the order to make a new permutation.

The problem is I can&#039;t figure out a callback that will fire when the columns are rearranged!

Do you have any thoughts? Ever seen anything similar?

Again, many thanks for a great blog.
Best,
Meade

&lt;pre lang=&quot;matlab&quot;&gt;
function legendFromHeaderGUI_ex()

GUI = figure(&#039;Position&#039;,[-10000 0 100 100],&#039;Name&#039;,&#039;Build Legend Name&#039;,...
    &#039;CloseRequestFcn&#039;,&#039;delete(gcf)&#039;,...
    &#039;UserData&#039;,0,...   
    &#039;Resize&#039;,&#039;on&#039;,...
    &#039;MenuBar&#039;, &#039;none&#039;,...
    &#039;ToolBar&#039;, &#039;none&#039;,...
    &#039;NumberTitle&#039;, &#039;off&#039;,...
    &#039;Visible&#039;,&#039;on&#039;);

RowName = {&#039;FileName&#039;,...
    &#039;Field1&#039;,...
    &#039;Field2&#039;,...
    &#039;...&#039;,...
    &#039;FieldN&#039;}&#039;;

% Normal Table
columnformat = {&#039;logical&#039;,&#039;char&#039;};
t_data = repmat({false(1,1)},[length(RowName),1]);

t = uitable(&#039;Parent&#039;,GUI,...
    &#039;Data&#039;,[t_data, RowName],...
    &#039;ColumnName&#039;,{},...                
    &#039;RowName&#039;,{},...
    &#039;ColumnWidth&#039;, {40,300},...
    &#039;ColumnFormat&#039;, columnformat,...
    &#039;ColumnEditable&#039;, [true,false],...
    &#039;FontSize&#039;,9,...
    &#039;Tag&#039;,&#039;t1&#039;);

% Update figure size to close-fit the Header table
t.Position(3) = t.Extent(3);
t.Position(4) = t.Extent(4);

GUI.Position(3) = t.Extent(3)+400;
GUI.Position(4) = t.Extent(4)+200;

t.Position(1) = 10;
t.Position(2) = 150;

%%% Dynamic Table
t2 = uitable(&#039;Parent&#039;,GUI,...
    &#039;Data&#039;,{},...
    &#039;ColumnName&#039;,{},...                
    &#039;RowName&#039;,{},...
    &#039;ColumnWidth&#039;, {125},...
    &#039;ColumnFormat&#039;, {&#039;char&#039;},...
    &#039;ColumnEditable&#039;, false,...
    &#039;RearrangeableColumns&#039;,&#039;on&#039;,...
    &#039;FontSize&#039;,7,...    &#039;CellEditCallback&#039;,@updateLegend2
    &#039;Tag&#039;,&#039;t2&#039;);

t2.Position(3) = t2.Extent(3);
t2.Position(4) = t2.Extent(4);

%% JAVA for UITABLES
t2_jscrollpane = findjobj(t2,&#039;-nomenu&#039;);  
t2_jtable = t2_jscrollpane.getViewport.getView;

t.CellEditCallback = {@t1_callback,t2_jtable};

% vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
%%% t2_jtableh = handle(t2_jtable,&#039;CallbackProperties&#039;)         % I&#039;m just lost
%%% t2.#??CALLBACKHERE# = {@t2_Callback,ht_jtable};
% ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

com.mathworks.mwswing.MJUtilities.initJIDE;
com.jidesoft.grid.TableUtils.autoResizeAllColumns(t2_jtable);

gd.Handles = guihandles(GUI);
guidata(GUI,gd);

movegui(GUI,&#039;center&#039;);

    function t1_callback(hObj,~,~)
        h = guidata(hObj);
        headers = hObj.Data(:,2);
        flags   = [hObj.Data{:,1}]&#039;;
        h.Handles.t2.ColumnName = headers(flags);
        h.Handles.t2.Position(3) = h.Handles.t2.Extent(3);
        h.Handles.t2.Position(4) = h.Handles.t2.Extent(4);       
    end

    function t2_Callback(hObj,evt,t2_jh)
        % HOW CAN I FIRE YOU!!!?!?!???
    end
end
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>Hi Yair,</p>
<p>I think I have a new problem, maybe you haven&#8217;t seen!</p>
<p>I&#8217;m using a uitable to make an interactive name builder.  Basically, I&#8217;m creating a table with dynamic column names.  The user can then change the order to make a new permutation.</p>
<p>The problem is I can&#8217;t figure out a callback that will fire when the columns are rearranged!</p>
<p>Do you have any thoughts? Ever seen anything similar?</p>
<p>Again, many thanks for a great blog.<br />
Best,<br />
Meade</p>
<pre lang="matlab">
function legendFromHeaderGUI_ex()

GUI = figure('Position',[-10000 0 100 100],'Name','Build Legend Name',...
    'CloseRequestFcn','delete(gcf)',...
    'UserData',0,...   
    'Resize','on',...
    'MenuBar', 'none',...
    'ToolBar', 'none',...
    'NumberTitle', 'off',...
    'Visible','on');

RowName = {'FileName',...
    'Field1',...
    'Field2',...
    '...',...
    'FieldN'}';

% Normal Table
columnformat = {'logical','char'};
t_data = repmat({false(1,1)},[length(RowName),1]);

t = uitable('Parent',GUI,...
    'Data',[t_data, RowName],...
    'ColumnName',{},...                
    'RowName',{},...
    'ColumnWidth', {40,300},...
    'ColumnFormat', columnformat,...
    'ColumnEditable', [true,false],...
    'FontSize',9,...
    'Tag','t1');

% Update figure size to close-fit the Header table
t.Position(3) = t.Extent(3);
t.Position(4) = t.Extent(4);

GUI.Position(3) = t.Extent(3)+400;
GUI.Position(4) = t.Extent(4)+200;

t.Position(1) = 10;
t.Position(2) = 150;

%%% Dynamic Table
t2 = uitable('Parent',GUI,...
    'Data',{},...
    'ColumnName',{},...                
    'RowName',{},...
    'ColumnWidth', {125},...
    'ColumnFormat', {'char'},...
    'ColumnEditable', false,...
    'RearrangeableColumns','on',...
    'FontSize',7,...    'CellEditCallback',@updateLegend2
    'Tag','t2');

t2.Position(3) = t2.Extent(3);
t2.Position(4) = t2.Extent(4);

%% JAVA for UITABLES
t2_jscrollpane = findjobj(t2,'-nomenu');  
t2_jtable = t2_jscrollpane.getViewport.getView;

t.CellEditCallback = {@t1_callback,t2_jtable};

% vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
%%% t2_jtableh = handle(t2_jtable,'CallbackProperties')         % I'm just lost
%%% t2.#??CALLBACKHERE# = {@t2_Callback,ht_jtable};
% ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

com.mathworks.mwswing.MJUtilities.initJIDE;
com.jidesoft.grid.TableUtils.autoResizeAllColumns(t2_jtable);

gd.Handles = guihandles(GUI);
guidata(GUI,gd);

movegui(GUI,'center');

    function t1_callback(hObj,~,~)
        h = guidata(hObj);
        headers = hObj.Data(:,2);
        flags   = [hObj.Data{:,1}]';
        h.Handles.t2.ColumnName = headers(flags);
        h.Handles.t2.Position(3) = h.Handles.t2.Extent(3);
        h.Handles.t2.Position(4) = h.Handles.t2.Extent(4);       
    end

    function t2_Callback(hObj,evt,t2_jh)
        % HOW CAN I FIRE YOU!!!?!?!???
    end
end
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: didi		</title>
		<link>https://undocumentedmatlab.com/articles/uitable-sorting#comment-406623</link>

		<dc:creator><![CDATA[didi]]></dc:creator>
		<pubDate>Sat, 13 May 2017 16:55:46 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2391#comment-406623</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/uitable-sorting#comment-406398&quot;&gt;Jack&lt;/a&gt;.

Thank! It&#039;s helped me a lot!]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/uitable-sorting#comment-406398">Jack</a>.</p>
<p>Thank! It&#8217;s helped me a lot!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/uitable-sorting#comment-406432</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 10 May 2017 11:18:01 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2391#comment-406432</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/uitable-sorting#comment-406427&quot;&gt;Jack&lt;/a&gt;.

&lt;i&gt;jtable.getSortedRowAt(rowIndex)&lt;/i&gt; returns the display row index for a specified data model row;
&lt;i&gt;jtable.getActualRowAt(rowIndex)&lt;/i&gt; returns the data model row index for a specified display row.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/uitable-sorting#comment-406427">Jack</a>.</p>
<p><i>jtable.getSortedRowAt(rowIndex)</i> returns the display row index for a specified data model row;<br />
<i>jtable.getActualRowAt(rowIndex)</i> returns the data model row index for a specified display row.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jack		</title>
		<link>https://undocumentedmatlab.com/articles/uitable-sorting#comment-406427</link>

		<dc:creator><![CDATA[Jack]]></dc:creator>
		<pubDate>Wed, 10 May 2017 10:26:34 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2391#comment-406427</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/uitable-sorting#comment-406419&quot;&gt;Yair Altman&lt;/a&gt;.

Hi Yair

Thank you very much for your answer.
Can you explain me please what is the meaning of the index that getSortedRowAt is returning? I noticed it is&#039;nt the row index before the table sorted.

Thanks,
Jack]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/uitable-sorting#comment-406419">Yair Altman</a>.</p>
<p>Hi Yair</p>
<p>Thank you very much for your answer.<br />
Can you explain me please what is the meaning of the index that getSortedRowAt is returning? I noticed it is&#8217;nt the row index before the table sorted.</p>
<p>Thanks,<br />
Jack</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/uitable-sorting#comment-406421</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 10 May 2017 08:24:04 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2391#comment-406421</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/uitable-sorting#comment-400355&quot;&gt;shi&lt;/a&gt;.

@shi - this is an unhandled case in the &lt;code&gt;ColoredFieldCellRenderer&lt;/code&gt; code. You have the source code for this class - it is quite simple and you can modify it in a which that will handle sorted data rows.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/uitable-sorting#comment-400355">shi</a>.</p>
<p>@shi &#8211; this is an unhandled case in the <code>ColoredFieldCellRenderer</code> code. You have the source code for this class &#8211; it is quite simple and you can modify it in a which that will handle sorted data rows.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/uitable-sorting#comment-406419</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 10 May 2017 08:19:28 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2391#comment-406419</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/uitable-sorting#comment-406398&quot;&gt;Jack&lt;/a&gt;.

@Jack - sorting only affects the way that the table-model data is displayed, it does not affect the data itself. You can get the model-to-view mapping using this:
&lt;pre lang=&quot;matlab&quot;&gt;displayedRowIndex = jtable.getSortedRowAt(modelRowIndex-1) + 1;&lt;/pre&gt;
Note that java indices start at 0 (not 1 as in Matlab), hence the need for the -1 and +1 in the code snippet above.
When the table is not sorted, &lt;code&gt;displayedRowIndex&lt;/code&gt; will be the same as &lt;code&gt;modelRowIndex&lt;/code&gt;; when sorted it will return a different index.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/uitable-sorting#comment-406398">Jack</a>.</p>
<p>@Jack &#8211; sorting only affects the way that the table-model data is displayed, it does not affect the data itself. You can get the model-to-view mapping using this:</p>
<pre lang="matlab">displayedRowIndex = jtable.getSortedRowAt(modelRowIndex-1) + 1;</pre>
<p>Note that java indices start at 0 (not 1 as in Matlab), hence the need for the -1 and +1 in the code snippet above.<br />
When the table is not sorted, <code>displayedRowIndex</code> will be the same as <code>modelRowIndex</code>; when sorted it will return a different index.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jack		</title>
		<link>https://undocumentedmatlab.com/articles/uitable-sorting#comment-406398</link>

		<dc:creator><![CDATA[Jack]]></dc:creator>
		<pubDate>Wed, 10 May 2017 01:04:39 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2391#comment-406398</guid>

					<description><![CDATA[Hi Yair

How can I make the table.Data to be update after i&#039;m sorting a table as like as you described above?
Because I noticed that after i&#039;m sorting a table the table.Data remains the same as before i sorted the table and actually disconnect what the table showing to the user.

TNX

Jack]]></description>
			<content:encoded><![CDATA[<p>Hi Yair</p>
<p>How can I make the table.Data to be update after i&#8217;m sorting a table as like as you described above?<br />
Because I noticed that after i&#8217;m sorting a table the table.Data remains the same as before i sorted the table and actually disconnect what the table showing to the user.</p>
<p>TNX</p>
<p>Jack</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
