How to render the boolean field

LabKey Support Forum (Inactive)
How to render the boolean field feifei bao  2015-04-20 09:51
Status: Closed
 
Hi,

I have a list in my wiki page. For one specific column, I want it can render the boolean field with other text. If boolean value is false, it displays "create" with a specific URL. Otherwise, it displays "download" which is linked to download page. I think it should be realized in "Schema Browser". Could someone help me of this?

Thank you very much.

Feifei
 
 
Jon (LabKey DevOps) responded:  2015-04-20 14:21
Hi Feifei,

I want to make sure I'm understanding you correctly here.

You want to customize the way your list renders a boolean value so it would display a specific link in lieu of saying True or False?

Regards,

Jon
 
feifei bao responded:  2015-04-20 15:25
Hi Jon,

Yes, your understanding is right. That is what I want to do.

Feifei
 
Jon (LabKey DevOps) responded:  2015-04-20 15:54
Hi Feifei,

Thanks for confirming. I do not believe that this is possible. The XML Metadata section will not allow a URL to be rendered based on conditional formatting and the Javascript API doesn't have anything showing the ability to change a rendered QueryWebPart to alter how a boolean value to utilize a link in lieu of the True/False value.

I will confirm my information here, but it looks like the only way you'd be able to accomplish this is not by rendering the list via a QueryWebPart but as just a selectRows call and build a table to render your data instead so you can replace the boolean value with your download & create links.

Regards,

Jon
 
Jon (LabKey DevOps) responded:  2015-04-20 17:32
Hi Feifei,

Just curious, can you show me an example of the Create and the Download links?

I was thinking about possibly you using a CASE in your SQL query to change the text from true and false to any other text you'd want to render. The Query Web Part will also render any HTTP URLs as clickable as well automatically. However, what will dictate a Create URL vs a Download URL that would be unique to each record?

Regards,

Jon
 
feifei bao responded:  2015-04-20 17:51
Hi Jon,

Sure. I have a wiki page shows the participant list and another page shows the table to insert a new row of the list. Once I insert a new row, the boolean column('Report') return false value and show "Create" link. After clicking the link, the page goes to a generating report page. Once the user creates the report, the 'Report' column in the list returns true and display 'Download' link. This link can be used to download the created report.

I hope I explain it clearly enough.

Thank you very much.

Feifei
 
Jon (LabKey DevOps) responded:  2015-04-20 17:59
Hi Feifei,

I know you want a create link to show up. What I'm asking you is where is this create link supposed to point to? I need to see an example of the URL and an example of the URL for the download link.

Regards,

Jon
 
feifei bao responded:  2015-04-20 18:05
Hi Jon,

I see. For example, 'List' main page URL: https://flubigdata.circ.rochester.edu/labkey/project/Feifei%20Project/GeneProject/begin.view?
                              'Create' URL: https://flubigdata.circ.rochester.edu/labkey/project/Feifei%20Project/GeneProject/begin.view?pageId=Variant%20Selection
                              'Download' URL: https://flubigdata.circ.rochester.edu/labkey/project/Feifei%20Project/GeneProject/begin.view?pageId=Report%20Download

Best regards,

Feifei
 
Jon (LabKey DevOps) responded:  2015-04-20 21:04
Thanks Feifei,

So I did find another way to do this. It isn't exactly what you asked for, but it is close.

This requires you to do the following:

1. Create a new query off of your existing list via the Schema Browser. To create a new query, just select your list in the schema browser and click on "Create New Query".
2. In your new query, you will want to do the following:
   - Add the Primary Key field to your query or whatever field is going to be used to identify the specific record
   - Update the boolean field to use a CASE. See my example below:

SELECT TestBool.Key,
TestBool.Name,
CASE WHEN TestBool.download = false THEN 'Variant Selection' ELSE 'Download Report' END AS url
FROM TestBool

The query above is tied to a basic list that just has the Key value, a name field, and a download option that appears as a checkbox to do the boolean value. The CASE will use the words "Variant Selection" if the download is false and "Download Report" if it's true.

3. After the query is saved, you will update the XML Metadata for the field where the case is being used ("url" in my example). So you will go into the Edit Metadata section of the query and add the following to the URL field that corresponds with the boolean field:

/labkey/project/Feifei%20Project/GeneProject/begin.view?pageId=${url}&recordId=${Key}

This will then create a query off of the list and it will be a link to a specific page (Variant Selection or Report Download) based on whether it's true or false and it will also pass along the ID of the record in the list.

Does this make sense?

Regards,

Jon
 
feifei bao responded:  2015-04-21 12:06
Hi Jon,

Thank you for your detailed explanation. I tried as you said. It works! Great!

Thank you very much.

For a certain list, the 'Import Data' has two choices(1.Upload file; 2.Copy/paste text). How can I move this interface to my own wiki page and delete "Import Data" button on the list? Can I delete "Copy/paste text" and only leave "upload file" function?

Best regards,

Feifei
 
Jon (LabKey DevOps) responded:  2015-04-21 13:56
Hi Feifei,

You can remove or change what the button does either via Javascript or via the XML Metadata.

Just like what we covered here: https://www.labkey.org/announcements/home/Developer/Forum/thread.view?rowId=10597, you can either use XML Metadata to alter your buttonbar or use Javascript to do it within the wiki page.

You can replace Import Data button with a different button altogether and have it point to your wiki page in lieu of it going to the standard default page the list will use for the import.

XML Reference Source: https://www.labkey.org/wiki/home/Documentation/page.view?name=customButtonBars
Javascript Reference Source: https://www.labkey.org/download/clientapi_docs/javascript-api/symbols/LABKEY.QueryWebPart.html#constructor

Regards,

Jon
 
feifei bao responded:  2015-04-23 13:22
Hi Jon,

 As you suggested before, I create a new query off of my list via the Schema Browser. For this query, the default view does not show the "selection box", "EDIT" and "DETAILS" columns. I want to customize this function to my query.

So I tried this coding in XML Metadata:

 <ns:buttonBarOptions alwaysShowRecordSelectors = "true">
 </ns:buttonBarOptions>

It always shows "Error : Attribute not allowed (no wildcards allowed): alwaysShowRecordSelectors in element buttonBarOptions@http://labkey.org/data/xml"

But I tried:

    <ns:buttonBarOptions includeStandardButtons="true">
    </ns:buttonBarOptions>

It is OK.

Actually I am not sure whether this function can solve my problem.

Thank you very much.

Feifei
 
Jon (LabKey DevOps) responded:  2015-04-23 16:41
Hi Feifei,

Those Edit and Details columns are only accessible from the original built-in queries & tables for the Lists, not for the user-defined queries. I'm not sure why you're looking to have the edit and details options there when you previously said that you wanted the Boolean value to generate a link that would take the user to a wiki that would then update the table of the original list, thereby not requiring an Edit or Details column.

Regards,

Jon
 
feifei bao responded:  2015-04-24 07:43
Hi Jon,

Because the boolean value is used to generate a report related with the participant rather than delete or edit the row in the list.

Best regards,

Feifei
 
Ben Bimber responded:  2015-04-24 07:55
Hi Feifei,

I think there's another avenue that might help you here. It's not used often, but columns can have a custom onClick handler added through XML. Rather than try to change the URL of this column, you could add some JS code such that when you click the column it will conditionally do whichever behavior is appropriate. Here's a rough example of what it might do:

<column columnName="Id">
    <displayColumnFactory>
        <className>org.labkey.api.data.JavaScriptDisplayColumnFactory</className>
        <properties>
            <!--this is a JS file containing the handler to be called. While you could write the JS code in the onClick handler below, but debugging will be easier if separated-->
            <property name="dependency">myModule/myCode.js</property>
            <!-- this will call your code, passing in the column's value. your handler can take this information and do whatever is appropriate-->
            <property name="javaScriptEvents">onClick="MyModule.onBooleanFieldClick('${FieldNameHere}');"');"</property>
        </properties>
    </displayColumnFactory>
</column>


You could probably also use variations on this to modify the text you display, meaning you dont see a separate SQL statement, and avoid the problems with editability.