How to display image in column;
How to display image in column;
Hi there,
Can somebody explain me how to display images in a column. I have checked the examples but could not understand (by lacking of jquery experience). I would like to render images based on the url of the image.
I have checked these, but I did not find image related examples (or flags in the examples came serverside).
https://datatables.net/examples/basic_init/data_rendering.html
https://datatables.net/reference/option/columns.render
https://datatables.net/manual/data/renderers#Functions
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
Answers
Are you able to display the image based on the URL outside of Datatables? Can you provide us an example of what you want to render? Please provide a simple test case showing an example of what you are trying to render. It doesn't need to be in a table or Datatables.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Hi there,
I would like to render an image based on the URL of the image file displayed in the column.
<img src="url/image.jpg">
This example should help, it's showing different styles of rendering, including images,
Colin
Thank you,
I tried similar solutions but only a picure icon shows up in the list. Could you have a look at my code?
I don't thin you will be able to access a local file this way. Please see this Stack Overflow thread for a discussion about accessing a local file with the
img
element.Kevin
Hi,
The problme was sorted by using relative URLs. It shows the images now but it seems started blinking once AJAX refreshes the database (json file). Can you help me how to stop the blinking effect?
Please post a link to your page or a test case replicating the issue so we can see how this update is working to offer suggestions.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Please find code below;
Thanks for the code but its difficult to troubleshoot these types of errors without actually seeing them. I built this simple test case that uses your setTimeout function for
ajax.reload()
every 2 seconds.http://live.datatables.net/bemaketa/1/edit
Guessing this is where the problem is you are trying to fix. There is no blinking in the test case. Please update the test case or provide a link to show the problem.
Maybe the ajax response takes awhile to be returned causing the blinking. Look at the browser's network inspector to see how long it takes.
Kevin
Hi there,
I tried with two different scenario;
One with yours, where the Image was hosted on the web. There was no blinking.
One another, where the Image was loaded from the local drive. It was blinking every 2sec.
So, it is blinking when the images come from local. Is it a bug or can we fix it somehow?
As a test try loading one of your images locally outside of Datatables. I don't believe Datatables is doing anything with the images to cause them to blink. If you can provide a link to a test case showing the problem we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Hi Kevin,
Thank you for the feedback. Actually the image is not blinking, just it looks like when the whole table is reloading every 2 sec. The table disappear and reload sequencually every 2 sec.
Check for a delay in loading the data. If you are using
ajax.relaod()
to reload the data but you see the rows disappear and redisplay then there might be a delay in fetching the data. In that case you could use a jQuery ajax() request to fetch the data instead ofajax.relaod()
. in thesuccess
function useclear()
followed byrows.add()
to add the fetched rows. This way the row change is instantaneous when the new data is ready.Kevin
I am affraid, I need further help.
The code in the button click event handler you would use in your setTimeout function.
http://live.datatables.net/novadupo/1/edit
If you still need help debugging the issue then please provide a link to your page or a test case replicating the issue. Without that we will be guessing what the problem might be.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin