Transient column? Additional column in LIST view

Archived from the Xataface Users forum.

neotrode — Fri Mar 11, 2011 2:07 pm

Hello.

Is it easy enough to create an additional column in the list view that I can use to create a link next to each row to take me to an external page? The kicker is that the column is not associated with a field of any kind.

For example: It would be nice if I can add a link next to each row like this: view as pdf

Where “id=#” is a number based on the row being displayed.

I assume it would be a delagate class. Could you give us an idea of how to go about this?

Thanks.

-Frank


shannah — Sat Mar 12, 2011 1:15 pm

A little cheat that I often do in this case is I create a grafted field via the __sql__ directive in the fields.ini file. Then I override the renderCell method for this field in the delegate class to show the link.

You’ll also need to use the noLinkFromListView=1 directive on this field so that Xataface won’t try to wrap the whole cell in a link…

e.g. fields.ini

Code: Select all
`sql = “select t.*, null as mytransientfield from mytable t”

[mytransientfield]
    noLinkFromListView=1`

Delegate class:

Code: Select all
`…
function mytransientfield__renderCell($record){
    return ‘view as pdf’;
}

…`


neotrode — Tue Mar 29, 2011 8:09 am

Excellent solution. Thanks!


cookie720 — Mon Jul 09, 2012 7:51 pm

I think im on the right track by posting on this thread already. Im trying to do a similar thing. Trying to add a related column onto a tables list view. Can this be done?
The table is related already so you can see its data in details view. I just want to see that related column in list view, and if the record has more than 1 related record, show the most recent field.


shannah — Thu Jul 12, 2012 11:19 am

You’ll want to do a custom __sql__ query and graft the field onto your table.
e.g.

Code: Select all
__sql__ = "select b.*,     (         select relatedcol from relatedtable r where r.baseid=b.baseid order by r.created desc limit 1     ) as relatedcol     from basetable b"

NOte: Haven’t tested this.


cookie720 — Fri Jul 13, 2012 8:25 pm

is this sql query as you have written done it __sql___ put anywhere in the tables fields.ini? and then just below the query i do the [graftedfield]? am i correct?


shannah — Tue Jul 17, 2012 2:41 pm

It should be at the beginning of the fields.ini file.


cookie720 — Sun Jul 29, 2012 10:48 pm

Hello all.
Say I have a table with a grafted column coming from another table like such

fields.ini

Code: Select all
`sql = “SELECT b.*,
  (
        SELECT ReviewDate from status r WHERE r.MatterID=b.MatterID ORDER BY r.ReviewDate DESC LIMIT 1
    ) as ReviewDate
    from matters b”

[ReviewDate]
filter = 1
widget:label = “Review Date”
validators:required = false
vocabulary = ReviewDate
visibility:browse=hidden`

and then i wanted to by default only show rows where something = something like such

matters.php

Code: Select all
function __sql__(){ return "SELECT * FROM `matters` WHERE `User` = current user "; }

the grafted column “ReviewDate” disappears….
How can I somehow do the filter, before grafting that column?


shannah — Mon Jul 30, 2012 10:21 am

The __sql__() method in the delegate class completely overrides the __sql__ directive in the fields.ini file. If you are using the delegate class method, then make sure it includes all of the grafted fields that you need.

-Steve


cookie720 — Mon Jul 30, 2012 4:55 pm

Yeah this kinda coincides with this thread: http://xataface.com/forum/viewtopic.php?f=4&t=6868&p=30844#p30844
If I can figure the LoggedInUserName+YES/NO filter by default, without breaking my grafted ReviewDate column, both these threads will be resolved!

experimentation continues
Thankyou,