Custom display column for lookup

LabKey Support Forum (Inactive)
Custom display column for lookup yohan jarosz  2014-05-15 07:03
Status: Closed
 
Hello,
I'm wondering if it's possible to customize the display for column lookups (for lists).
I know that I have the 'title' field that I can set to one field and that I can also set it via XML with table metadata.
But what I want is to display 2 fields instead of just one.

For instance I have one 'antibody' table that have two fields that I want to display ('name' and 'number'),
Some antibodies have the same name, so when you have to set them from another table, it is not possible to know
which one to choose. It is really 'name' + 'number' that make them unique.

Then is it possible to generate the tittle field like these title = ${name} (${number}) for example?

My workaround for now is to add a 'display' field to that table that contains both 'name' and 'number' but it's not very straightforward as the same data needs to be entered twice.

best
 
 
Greg Taylor responded:  2014-05-19 09:30
Hi Yohan,
It is possible to customize the display for column lookups for specific tables when creating a java module. You could define the table in java and then add and customize the display column. I am not aware of a way to do this generally for lists however.
Greg
 
Andy Straw responded:  2014-05-19 11:06
I had a similar problem, and solved it as follows - not sure this will work for you:

I wrote a query that builds the combined display field. For your list, the query would be something like:

SELECT
   name || ' (' || number || ')' AS title,
   name,
   number,
   key
FROM
   Antibody

If you need to use this as the target of a lookup from some other List, Dataset, or Assay, you'll need to add XML metadata to the query to define a key field - otherwise, the query won't show up in the list of tables in the "lookup" drop-down when you are defining the type of the source field in that List, Dataset, or Assay. Something like this:

<tables xmlns="http://labkey.org/data/xml">
 <table tableName="QueryNameGoesHere" tableDbType="NOT_IN_DB">
   <columns>
     <column columnName="Key">
       <isKeyField>true</isKeyField>
     </column>
   </columns>
 </table>
</tables>

To get the "title" field to be the display column of the query (so it's used in the "lookup" dropdown), I made it the first column in the SELECT statement. There's probably a way to specify that in XML metadata instead.

Hope this helps.

Andy Straw
University of Rochester
 
yohan jarosz responded:  2014-05-19 23:30
@Andy
Perfect !! I didn't thought about it myself, but simple and straightforward. Many thanks.
BTW I even didn't need to edit table metadata as the query directly shows in the lookup drop down.


@Greg
Thank you. If I need more development I will definitely goes with building a module as it's seems more "customizable".