最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - DataTables selected rows data-attribute - Stack Overflow

programmeradmin6浏览0评论

I've got datatables set up nicely and with the select extension - I have this code for when someone uses a "report" and it loads another page using some cell content from the table to pass to the report. That works fine, however - I need to be able to pass a data-element of each <tr> of the table instead of the row data...

This is my current code:

var table = $('#table_search_project').DataTable();

//then re-run the code to get the selected rows
var id_list = $.map(table.rows('.selected').data(), function (item) {
    return item[1]
});

So you can see, I used to use item[1] to return, but I really want to be able to get the <tr> object so I can retrieve the data-something-id property (but I don't want to show it - hence the issue)

I've got datatables set up nicely and with the select extension - I have this code for when someone uses a "report" and it loads another page using some cell content from the table to pass to the report. That works fine, however - I need to be able to pass a data-element of each <tr> of the table instead of the row data...

This is my current code:

var table = $('#table_search_project').DataTable();

//then re-run the code to get the selected rows
var id_list = $.map(table.rows('.selected').data(), function (item) {
    return item[1]
});

So you can see, I used to use item[1] to return, but I really want to be able to get the <tr> object so I can retrieve the data-something-id property (but I don't want to show it - hence the issue)

Share Improve this question edited Aug 8, 2017 at 8:36 Chris asked Aug 8, 2017 at 8:26 ChrisChris 5701 gold badge4 silver badges20 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 17

I worked it out. Too hasty to ask in SO!

I used this instead:

var id_list = $.map(table.rows('.selected').nodes(), function (item) {
    return $(item).data("entity-id");
});

The nodes() collection sends me back the <tr> elements instead of the data. Exactly what I wanted. Found the information here:

https://datatables/reference/api/row().node()

发布评论

评论列表(0)

  1. 暂无评论