Inserting data-id and data-url into the Datatable extra field

Asked

Viewed 188 times

0

Look at this code

https://github.com/rg3915/frontend/blob/master/djfront/djbasic/templates/djbasic/customer_list_datatable.html#L53

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 the value I want.

Then I managed to insert a class into the 'tr' (which is a row)...

https://github.com/rg3915/frontend/blob/master/djfront/djbasic/templates/djbasic/customer_list_datatable.html#L58

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

But I cannot insert a data-id and data-url into this Row'.

I’ve tried to

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

But he doesn’t insert.

Question: as I enter a data-id and data-url inside the tr from Datatable?

Expected result:

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

1 answer

2


To insert the attribute use Jquery’s attr() function:

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

To recover this value, access the attribute as follows:

$(row).data('id');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.