Page 1 of 1

Customise returned data format on view tab

PostPosted: Mon Oct 29, 2012 4:13 am
by m23k
Hi

With the fieldname__renderCell() function I have been able to add for example "GB" to the output for HDD size storage on the list page. Ie. I have 250 stored in the database but it outputs it as "250 GB" in the list table.

How can I do this on the view page specific to the record though?

Thanks!

Re: Customise returned data format on view tab

PostPosted: Mon Oct 29, 2012 8:08 am
by shannah
You could actually hit two birds with one stone by just implementing the fieldname__display() method.

Re: Customise returned data format on view tab

PostPosted: Tue Oct 30, 2012 5:08 am
by m23k
Thanks, it even mentions that in the wiki I've just realised!

A heads up to others finding this thread:

Before I was using $record->display('field_name') in my fieldname__renderCell() function to display the value. This obviously went loopy (out of memory errors) when switching to using fieldname__display() function as it was doing its self in its self ;)

I changed to using $record->strval('fieldname') instead. Brill. Working.

Except.. I still need to want to add div's to my cells so I can not wrap them. So you use renderCell() as well still like this.

Ie:
Code: Select all
function ram__renderCell(&$record){
    return '<div style="white-space: nowrap;">'.$record->display('ram').'</div>';
}

function screen_size__display(&$record){
    return $record->strval('ram').' GB';
}

Re: Customise returned data format on view tab

PostPosted: Tue Oct 30, 2012 12:29 pm
by auphi
Good call on using $record->strval() in the fieldname__display(). I wish you'd posted this 2 weeks ago; it would have saved me a lot of frustration. =P

I don't know what your intentions are with wraping, but just to throw this out there, if you wanted to go ahead and make all of your cells nowrap, you can create your own custom style sheet (if you haven't already) and toss in

Code: Select all
.listing { white-space:nowrap; }

so that you don't have to manually do it for every cell.

Re: Customise returned data format on view tab

PostPosted: Wed Oct 31, 2012 2:50 am
by m23k
Thank you auphi!!

Yes, that indeed knocked that one on the head, and it applies it to the table headers aswell meaning I know longer have to use a div with min-width on certain fields too as that wasn't applying the no wrap to table headers just cells!

:D