Displaying an image in the Grid
- Single Page
Posted 10 June 2012 - 17:10 PM
How can I display the images in the GC Grid?
Posted 10 June 2012 - 17:21 PM
Posted 10 June 2012 - 22:00 PM
Couldn't a workaround be to use the [b]add_action [/b]function and pass the image as the URL? You could hide the column with the image file name but still get its value and use it as URL of the add_action image. You could even set the action of that button with the thumbnail to open the fullsize image on a new window or pop up.
I hope I was clear enough, if not let me know and I'll try to explain a littel further.
Check the documentation for add_action
http://www.grocerycrud.com/documentation/options_functions/add_action
Cheers.
Posted 10 June 2012 - 22:16 PM
Posted 11 June 2012 - 07:01 AM
Posted 11 June 2012 - 21:44 PM
Posted 12 June 2012 - 11:13 AM
Not displaying thumbnails nor uploading to the folder:
Posted 12 June 2012 - 23:31 PM
Posted 03 July 2012 - 11:07 AM
How can I display the images in the GC Grid?[/quote]
I've just solved this issue using callback_column:
// this is the column (named "fileUser" in the database) where the thumbnail must appear
$crud->callback_column('fileUser',array($this,'showImage'));
As you can see, within the callback_column statement there is a call to a function, showImage(); the function is defined this way:
// this is the string replaced within the cell - this example refers to a localhost location, change it according to your needs
function showImage($value) {
return "<img src='http://localhost/CI_Project/assets/uploads/files/" . $value . "' width=100>";
}
Then I render the GC output, and pass everything to the view as usual:
$output = $crud->render();
$this->_example_output($output);
Perhaps this is a naive solution, but for basic needs it works very well.
Posted 03 April 2013 - 18:45 PM
This is a very nice solution and I've added to my project...I have a question how do I save an image path to the database? for example "assets/uploads/files/cat.png" is save in the images table so I can reference it like you have illustrated above?
Thanks.
Posted 05 April 2013 - 16:13 PM
the path is predefined, so you just hardcode it before the filename.
Posted 25 August 2013 - 12:23 PM
I've just solved this issue using callback_column:
// this is the column (named "fileUser" in the database) where the thumbnail must appear $crud->callback_column('fileUser',array($this,'showImage'));As you can see, within the callback_column statement there is a call to a function, showImage(); the function is defined this way:// this is the string replaced within the cell - this example refers to a localhost location, change it according to your needs function showImage($value) { return "<img src='http://localhost/CI_Project/assets/uploads/files/" . $value . "' width=100>"; }Then I render the GC output, and pass everything to the view as usual:$output = $crud->render(); $this->_example_output($output);Perhaps this is a naive solution, but for basic needs it works very well.
And how can I do in edit mode? thanks!
Posted 25 November 2016 - 21:25 PM
I've just solved this issue using callback_column:
// this is the column (named "fileUser" in the database) where the thumbnail must appear $crud->callback_column('fileUser',array($this,'showImage'));As you can see, within the callback_column statement there is a call to a function, showImage(); the function is defined this way:// this is the string replaced within the cell - this example refers to a localhost location, change it according to your needs function showImage($value) { return "<img src='http://localhost/CI_Project/assets/uploads/files/" . $value . "' width=100>"; }Then I render the GC output, and pass everything to the view as usual:$output = $crud->render(); $this->_example_output($output);Perhaps this is a naive solution, but for basic needs it works very well.
You are really a genius !!!!
Posted 01 November 2017 - 08:01 AM
Yeap I understand what do you mean. And yes it is a good solution. The only thing that it is annoying to go to an image one by one. That's why I created image CRUD to have all the functionality in one page. For me grocery CRUD covers all of my needs for CRUD except if I want a photo gallery and that's why I created this library .Well I thing that [member='xcoder'] has his answer and he has to choose now
great!!!
Posted 13 January 2018 - 21:31 PM
Hello to all,
I have like similar issue here.
I am storing image in DB and on list grid I am getting that image in <img> tag (which is what I want) and it goes well. On edit page I am also getting image itself with link to be deleted - so far so good.
But on read page I am getting just link for opening image in new tab.
I tried solution of callback_field and it didn't work in this case - on read page there is still just link and not an image itself.
I tried to test it with conditional of state and it worked on edit page, for example but not on read page. On read page I am still having just link and not an image.
I narrowed it to line of 329 of library but can't take good result.
// this code block works if ('edit' == $crud->getState()) { $crud->callback_field('logo', function($value, $primaryKey) { $url = base_url('assets/uploads/files/'.$value); return "<img src='" . $url . "' width=100>"; }); } // this one does not if ('read' == $crud->getState()) { $crud->callback_field('logo', function($value, $primaryKey) { $url = base_url('assets/uploads/files/'.$value); return "<img src='" . $url . "' width=100>"; }); }
List:
Edit:
Read:
I also tried `callback_read_field()` but it raises error that says library doesn't have that method. I noticed something similar as array, but not as method.
Also, in docs for callback_read_field method is said it is available from 1.6.0 version although latest version is 1.5.8. It is confusing, isn't it?
Am I wrong in something here? How to get mutation of value on read page?
Goran,
Posted 14 January 2018 - 00:08 AM
Posted 15 January 2018 - 10:35 AM
Last version is 1.6.0. Check again on the download page
Thank you. It worked with 1.6.0
I was able to use next code:
$crud->callback_read_field('logo', function($value, $primaryKey) { return '<img src="/assets/uploads/files/'. $value .'" width=100>'; });
It would be good to include 1.6.0. into github.