Question: Datatables - On click from image

Question

Datatables - On click from image

Answers 2
Added at 2017-01-03 11:01
Tags
Question

I have a datatable populated by 4 fields via a Laravel route. That is fine and works great.

Additionally I have added 2 columns with icons, again that is fine. One is to show a sliding panel of information and one will be a link to more details.

I show these by rendering column info.

I wish to have an onlick event for one which will use the data in column 0 which is a key field. I have tried:

{
  "targets": [4], 
  "render": function ( data, type, full, meta ) {
            {return '<div align="center"><a href="#"><img src="{{ asset("siteicons/Info_Box_Blue.png") }}" id="trigger" onclick="ShowSlider( {{ ' + 0 + '}} )"></a></div>';}    
                                }
                    },

This is in the columnDefs, but clicking does not do anything - even if I put a simple alert.

Help, please!

Answers
nr: #1 dodano: 2017-01-03 13:01

Extra curly braces are there in your render function. Could u please remove and try it ?

"render": function ( data, type, full, meta ) {
            return '<div align="center"><a href="#"><img src="{{ asset("siteicons/Info_Box_Blue.png") }}" id="trigger" onclick="ShowSlider(0)"></a></div>';   
                                }
nr: #2 dodano: 2017-01-03 15:01
"render": function ( data, type, full, meta ) {
    return '<div align="center"><a href="#"><img src="{{ asset("siteicons/Info_Box_Blue.png") }}" id="trigger" onclick="ShowSlider(' + full[0] + ')"></a></div>';   
}

If you're trying to get data from the row add it like this.

Source Show
◀ Wstecz