Inserting data-id and data-url into extra DataTable field

0

See this code

defaultContent: '<i  class="fa fa-close pull-right js-customer-delete"style="color: #0066FF; text-decoration: none; cursor: pointer; margin-left:10px"data-id=""data-url=""></i> <i  class="fa fa-edit pull-right js-customer-edit"style="color: #0066FF; text-decoration: none; cursor: pointer"data-id=""data-url=""></i>'

I can insert an extra column into the DataTable with whatever value I want.

I've been able to insert a class into 'tr' (which is a row ) ...

link

$(row).addClass('tr-customer');

But I can not insert a 'data-id' and 'data-url' into this 'row'.

I've tried

$(row).data('id', 'valor_qualquer')

But it does not.

Question: How do I insert a 'data-id' and 'data-url' into the 'tr' from the DataTable?

Expected result:

<tr class="tr-customer" data-id="" data-url=""></tr>

    

asked by anonymous 23.04.2017 / 21:39

1 answer

2

To insert the attribute use the attr () function of Jquery:

$(row).attr('data-id', 'valor_qualquer');

To retrieve this value, access the attribute as follows:

$(row).data('id');
    
24.04.2017 / 04:15