rendercell doesnt display as expected in list view

Archived from the Xataface Users forum.

tomhousley — Mon Oct 19, 2009 2:21 pm

Hello,

I have two tables:

tbl_history

tbl_organisation

In list view for tbl_history, the organisation name is shown (which is generated because of the vocabulary in field.ini pulling that from valuelists.ini, and when clicked takes me to the correct record in the tbl_history.

When the organisation name is clicked in list view of tbl_history I want this to load the edit view of the organisation. I have achieved this by rendercell:

Code: Select all
function org_id__renderCell(&$record){ return '<a href="index.php?-action=browse&-table=tbl_organisation&org_id='.$record->strval('org_id').'">'.$record->val('org_id').'</a>'; }

This works, but the problem is the the organisation name is no longer shown, just the org_id.

If I change the code to:

Code: Select all
function org_id__renderCell(&$record){ return '<a href="index.php?-action=browse&-table=tbl_organisation&org_id='.$record->strval('org_id').'">'.$record->val('org_name').'</a>'; }

… then nothing is rendered in the cell.

How to I show the organisation name as defined in valuelists.ini ?

Any help would be gratefully received.

Many thanks, Tom


shannah — Mon Oct 19, 2009 4:14 pm

If you are using a vocabulary on the org_id field then you can just do:

$record->display(‘org_id’) instead of $record->val(‘org_id’).

the display method uses vocabulary values when available. val() and strval() do not.

It is sort of like a food chain:

val() : Returns the raw value (may be int, array, or string, etc..)

strval(): Returns the raw value converted to a string (basically how it is saved in the db).

display() : Returns a display-ready version of the data. This includes converting ids into their corresponding values as specified in a vocabulary.

htmlValue() : Like display but renders for HTML display. e.g. encodes special chars, uses
instead of \n etc..

-Steve


tomhousley — Tue Oct 20, 2009 12:43 am

Thank you Steve, works a treat.