Sorting of XUI tables - buggy?

Last Updated: 2006-10-24

'''Buggy or feature rich? You judge.'''

=Question by N.N.=

Table Controls in XUI dialogs have the ability to sort rows by clicking on the column header of each column. However, when this happens the actual XML for the table control in the XUI file does not change its strucure... it does not sort. In essence, the only sorting that occurs is how the rows appear in the table control. This creates issues when attempting to retrieve the correct selected row in a table control after the rows have been sorted.

For example... index 0 is Peach, index 1 is Grape, index 2 is Apple in the XUI xml. After sorting, the table control now appears sorted in the order of Apple, Grape, Peach. However, if I click on Apple (index 0 in appearance) and I query in the xml for the element that has an attribute of selected=true, I get index 0 which in the XML is Peach.

Is there a known fix for this? Or is there something else I need to do to get this working... or any other way anyone has figured out?

=Clay Helberg=

Try using the value attribute of the table control to get the selected row. It will give you the value of the first cell of the selected row, so it puts some constraints on how you structure your table - you have to make sure your first column is some kind of ID or key value. That was the only way I could get table selection to work at all. N.N.:

I looked at the value attribute... but for some reason when I change the selection the value attribute never changes. Do I have to manually update this value?

=Al P Romo=

We use the table control as a visual tool only. It can be configured to save the changes, but you will have to save and then review the xml for changes. Never tried this, but that's what it says in the help

We query the table control by providing an additional guid for the row in a hidden column. When the user selects a row, we reference the guid for relevant data we placed in the table, and reference the table control row id for the appropriately select table index.

If the user wants to go back the the original view, we have a column called order they can click on to sort back to original order. The column contains nothing more than a chronological list of numbers that were placed in as the each row was populated.

- We learned very quickly that if you programmatically fill the table control from an array, make sure you populate each row and 'ALL' of it's columns with something. If think you left a column blank epic filled it with your next column's value.

=Finally N.N again=

I just wanted to write a follow-up on this.

The value attribute was never changing because the table we were using was multiselect. When you select multiple things you cannot 2 of them for 1 value :P

So since we HAD to have multiselect we pursued the issue and found out that using Javascript in a XUI to find the selected row is *bugged* OH NOEZ! At least in 5.1 it is bugged and since our client already agreed to use 5.1 we had to stick with it. That is until phase 2 etc which will be a long time down the road.

For example:

var document = Application.event.target.ownerDocument; var activeAcl = new Acl; var tableControl = document.getElementById("tcCitations"); var nodelist = tableControl.getElementsByAttribute("selected", "true", 1); for (var i = 0; i &lt; nodelist.length; i++) { activeAcl.execute("insert_string -sgml '&lt;citation id="     + nodelist.item(i).getChildNodes.item(4).getFirstChild.nodeValue       + ">"       + nodelist.item(i).getChildNodes.item(3).getFirstChild.nodeValue       + "&lt;/citation>'"); }

This will ALWAYS return the row at the index of selection in the ORIGINAL make up of the table control regardless of sorting. So what we found out is that the ACL methods of determining the selected rows are not bugged. So we went to code this like eventually to fix the issue:

var ret = Acl.eval('dlgitem_get_select_array($global_XUIWindow, "tcCitations", $arr);'); var count = Acl.eval('count($arr);'); for (var i = 1; i &lt;= count; i++) { Acl.execute("$context_yes_no = context_full_paths($test_array, 'citation', 1);"); Acl.execute("if ($context_yes_no == 1) {        insert_string -sgml '&lt;citation id="         + Acl.eval('dlgitem_get_table_cell_at($global_XUIWindow, "tcCitations", $arr['+i+'], 8);')         + ">"         + Acl.eval('dlgitem_get_table_cell_at($global_XUIWindow, "tcCitations", $arr['+i+'], 4);')         + "&lt;/citation>';         }         else {            message " + quot + error1Message + quot         + "; }"); }

''Editors Note by Liz Fraley:

This page was odd and hard to migrate. As best I can tell, you're substituting the following into the above code:

if ($context_yes_no == 1) { insert_string -sgml 'YYY '; } else { message 'error1Message'; } XXX = Acl.eval('dlgitem_get_table_cell_at($global_XUIWindow, "tcCitations", $arr['+i+'], 8);') YYY = Acl.eval('dlgitem_get_table_cell_at($global_XUIWindow, "tcCitations", $arr['+i+'], 4);') ''