Page 1 of 1

Transient column? Additional column in LIST view

PostPosted: Fri Mar 11, 2011 2:07 pm
by neotrode
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: <a target="_blank" href="htp://www.fakedomain.com/viewpdf.php?table=some-table&id=1">view as pdf</a>

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

Re: Transient column? Additional column in LIST view

PostPosted: Sat Mar 12, 2011 1:15 pm
by shannah
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 '<a target="_blank" href="...">view as pdf</a>';
}

...

Re: Transient column? Additional column in LIST view

PostPosted: Tue Mar 29, 2011 8:09 am
by neotrode
Excellent solution. Thanks!

Re: Transient column? Additional column in LIST view

PostPosted: Mon Jul 09, 2012 7:51 pm
by cookie720
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.

Re: Transient column? Additional column in LIST view

PostPosted: Thu Jul 12, 2012 11:19 am
by shannah
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.

Re: Transient column? Additional column in LIST view

PostPosted: Fri Jul 13, 2012 8:25 pm
by cookie720
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?

Re: Transient column? Additional column in LIST view

PostPosted: Tue Jul 17, 2012 2:41 pm
by shannah
It should be at the beginning of the fields.ini file.

Re: Transient column? Additional column in LIST view

PostPosted: Sun Jul 29, 2012 10:48 pm
by cookie720
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?

Re: Transient column? Additional column in LIST view

PostPosted: Mon Jul 30, 2012 10:21 am
by shannah
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

Re: Transient column? Additional column in LIST view

PostPosted: Mon Jul 30, 2012 4:55 pm
by cookie720
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,