Display column for lookup

LabKey Support Forum
Display column for lookup jdutra  2012-06-07 13:35
Status: Closed
 
I'm a little confused about the display column for a lookup. If I have a lookup field abc in a dataset (which links to a list), how is it determined which column from the specified list shows up in the grid? For instance, if I go to the dataset and choose Customize View, abc appears with a plus sign next to it. I can click on the plus sign to manually select one of the columns from the list for display.

But I can also check the box next to abc (which is how it is done by default). When I look at our current datasets, and the box next to abc is the only one checked, sometimes the dataset displays the list's key column. Sometimes it displays a different column. We must have set something differently either in the datasets or the lists to make that happen, but I can't figure out what!

A related question: if I run getMetaData() on a SelectRowsResponse of a dataset with a lookup field, how does it determine the value of fields.lookup.displayColumn? It doesn't seem to be returning the column I have manually selected for the default view.

Any help is appreciated,
- Jen
 
 
trent responded:  2012-06-07 16:35
Hi,

Lists have a titleField: https://www.labkey.org/wiki/home/Documentation/page.view?name=editListDesign.

You can also add some xml to the list. The titleColumn tells what is displayed: https://www.labkey.org/download/schema-docs/xml-schemas/schemas/tableInfo_xsd/elements/titleColumn.html

e.g.

<ns:tables xmlns:ns="http://labkey.org/data/xml">
  <ns:table tableName="People" tableDbType="NOT_IN_DB">
    <ns:titleColumn>Gender</ns:titleColumn>
  </ns:table>
</ns:tables>

If you specify a title field using the UI and in XML metadata, I believe the XML gets precedence (at least that was the case from my quick test).

"the box next to abc is the only one checked, sometimes the dataset displays the list's key column. Sometimes it displays a different column." - if there is no value in the title field, it shows up like: <1> where 1 is the PK value. Maybe that's what's happening?
 
jdutra responded:  2012-06-11 13:02
Thanks for your help. Somehow I never noticed the titleField. We have it set to auto for all our lists, and that's why I'm getting the strange (to me) behavior with the default column being displayed. As described in the help, AUTO makes the display field be the first String field. So, if the list has a string key, by default the key is also the display field. If the list's key is an integer, then the first string field is the one displayed.