Show an image in grid

QuestionsShow an image in grid
Jim asked 8 years ago

I have a table with one field that has the filename of an image.jpg that is held in a path on the server. I would like to display a thumbnail of the image in the grid.

I could name the thumbnail with the id of the record +.jpg.

Any ideas on how I can accomplish this?

3 Answers
Abu Ghufran answered 8 years ago

For such case, you need to define column with custom html as formatter.

$col = array();
$col["title"] = "Logo";
$col["name"] = "logo";
$col["width"] = "40";
$col["align"] = "center";
$col["search"] = false;
$col["sortable"] = false;
$col["default"] = "<img height=25 src='http://website.com/{image_name}.png'>";
$cols[] = $col;

{image_name} in default, need that there is another column defined with this name.

Alternate option is, if you db contains complete URL of image or you can concat it in custom SQL, you can use this

$col["formatter"] = "image"; // format as image — if data is image url e.g. http://<domain>/test.jpg
$col["formatoptions"] = array("width"=>'20',"height"=>'30'); // image width / height etc

Regards

Jim answered 8 years ago

That works way to easy…

I renamed the images to the id field of the table and was able to use this:

$col["link"] = "detail.php?id={id}";
$col["linkoptions"] = "target='_self'";
$col["default"] = "<img height=35 src='images/{id}.jpg'>";

as you can see you can still have the image clickable with the linkoptions set.

Very nice grid, thanks for all your hard work on it.

Jim

Abu Ghufran answered 8 years ago

Thanks, and let me know in case of further support or wishlist.

Your Answer

17 + 17 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?