javascript - add multiple custom attributes to datatables row -
i have table created in datatables 1.10:
var table = $('#table').datatable( { "data" : dataset, "binfo": false, "bfilter" : false, paging: false, "createdrow" : function (row,data,index) { $('td',row).eq(0).attr('id', 'cost-' + index); $('td',row).eq(1).attr('id', 'resale-' + index); deleteimage = $('<img />').attr('src', '../../img/details_close.png'); $('td',row).eq(0).append(deleteimage); $('td',row).eq(0).addclass( 'icons' ); }, "columns" : [ { title : 'cost' }, { title : 'resale' }, ], "columndefs": [ { classname: "details-control", "targets": [ 0 ] } ] });
this works fine. trying add image first <td>
using following code:
deleteimage = $('<img />').attr('src', '../../img/details_close.png'); $('td',row).eq(0).append(deleteimage); $('td',row).eq(0).addclass( 'icons' );
this works fine. adds image, , adds class particular <td>
.
my issue want add id
image can call click event
using javascript, of attempts far have not worked, including:
deleteimage = $('<img />').attr('src', '../../img/details_close.png', 'id','deleteline');
and
deleteimage = $('<img />').attr('src', '../../img/details_close.png'); deleteid = $('<img />').attr('id', 'deleteline'); $('td',row).eq(0).append(deleteimage); $('td',row).eq(0).append(deleteid);
(this second 1 add <img id="deleteline">
page, it's separate image inserted $('td',row).eq(0).append(deleteimage);
, doesn't me.)
i can't figure out exact syntax work.....
here's how in case else comes across same question:
deleteimage = $('<img />').attr({ src:'../../img/details_close.png',id:'deleteline'});
just wrap various elements you're trying add in { }, separated each comma.
Comments
Post a Comment