Grid: How to add a column showing a picture

147 views
Skip to first unread message

Armin Hierstetter

unread,
Aug 12, 2012, 10:01:48 AM8/12/12
to agile-too...@googlegroups.com
Hello to all of you,

I have a grid showing user messages that are sent to each other. The grid shows the sender's name, the title of the message, etc. I want to include a thumbnail picture of the user in the grid to make it look nicer,  like this, for example

         Name      Title        Sent
--------------------------------------------
  -----
  |PIC|  Peter     Hello        2012-8-2
  -----
  -----
  |PIC|  Sarah     Hi there     2012-8-2
  -----
  -----
  |PIC|  Frank     Oops!        2012-8-2
  -----

 
I see that there is addColumn with the option 'html' but I don't get it how to populate the column. Let's assume that the thumbnail file of a user is simply 1.jpg (for user with ID 1), 2.jpg (for user with ID 2) and so on.

How would I populate the column with html like in every row like

<img src='1.jpg' height='50' width='50'>

Maybe somebody can help me here?

Best


Armin

Armin Hierstetter

unread,
Aug 12, 2012, 10:25:37 AM8/12/12
to agile-too...@googlegroups.com
Just found a solution but not sure if that is how it's supposed to be:

<?
class MessageReceivedGrid extends Grid {
function init(){
parent::init();

$g = $this;

$g->addColumn('picture','sender_id', false);
$g->setModel('Model_MessagesReceived', array( 'sender_name', 'title', 'created' ));
}

function format_picture($field){
$this->current_row_html[$field] = "<img src='" . $this->current_row[$field] . ".jpg' height='50' width='50'>";
}
}

Romans Malinovskis

unread,
Aug 12, 2012, 7:44:57 PM8/12/12
to agile-too...@googlegroups.com
This is the correct way. You can also use "template" field type.

Gowrav Vishwakarma

unread,
Aug 15, 2012, 11:53:02 PM8/15/12
to agile-too...@googlegroups.com
Template is more easier for this I think,

Armin Hierstetter

unread,
Aug 16, 2012, 6:57:23 AM8/16/12
to agile-too...@googlegroups.com
Template is a great idea, but how can I provide my template that I would like to store? When trying this

template.html
<img src='/images/user/<?$user_id?>.jpg' width='50' height='50'>

and this code on my page:

$template = $this->add('SMLite');
$template->loadTemplate('template');

$g->addColumn('template','user_id', false)->setTemplate( $template->render() );

Then it's already rendered. But I want to pass the UNRENDERED template file.


Armin Hierstetter

unread,
Aug 16, 2012, 7:18:33 AM8/16/12
to agile-too...@googlegroups.com
This works:

$g->addColumn('template','user_id', false)->setTemplate(file_get_contents('templates/default/grid/image.html'));
$g->setModel('Model_MessagesReceived', array( 'user', 'title', 'created' ));

But this is kinda hack. I need the raw template to be set in setTemplate as if I do it like written above the SMLite engine will not know what to do with the tag <?$user_id?> and leaves it empty. So how should I do it?

Romans Malinovskis

unread,
Aug 17, 2012, 7:39:54 AM8/17/12
to agile-too...@googlegroups.com
Hi Armin.

Copy “format_template” and “init_template” methods from Grid_Advanced into your own Grid class, rename them and make them suitable for you and universal enough. Shouldn’t be complex. Then you can post them here, I’l create a template and will write some basic documentation on how to use it.

SMLite eats templates pretty well, setTemplate() could have been changed too.

Romans

--
FYI: If amount of emails you receive from this group is too much - switch to "Digest" mode. You'll receive no more than 1 email per day.
 
To post to this group, send email to
agile-too...@googlegroups.com
 
To unsubscribe and view archive:
http://groups.google.com/group/agile-toolkit-devel?hl=en
 
To download Agile Toolkit, visit:
http://agiletoolkit.org/

--
Romans is the author of a revolutionary Web Development Framework 
Agile Toolkit (www.agiletoolkit.org), which is offered under Open Source
License. Please show your support by raising awareness (tell your friends
about it) or referring any commercial web development projects towards
our skilled developer team (http://www.agiletech.ie/company/)

Here is a 25-minute video explaining why Agile Toolkit is awesome:



Message has been deleted

Peter Wechtersbach

unread,
Mar 3, 2014, 7:19:47 PM3/3/14
to agile-too...@googlegroups.com
I found this solution to be the easiest:

$grid->addColumn('link','image')->setTemplate('<img src="<?$pic_square?>" alt="<?$name?>" height="42" width="42" />');

Greetings Peter
Reply all
Reply to author
Forward
0 new messages