2017-08-08 36 views
0

我有很好的datatables設置和選擇擴展 - 我有這個代碼當有人使用「報告」,它加載另一個頁面使用表中的一些單元格內容傳遞給那個報告。這工作正常,但是 - 我需要能夠通過該表,而不是行數據的每個<tr>data-element ...DataTables selected rows data-attribute

這是我當前的代碼:

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] 
}); 

所以你可以看到,我曾經使用item[1]返回,但我真的想能夠獲得<tr>對象,所以我可以檢索data-something-id屬性(但我不想顯示它 - 因此問題)

回答

1

我工作過出。太急於在SO中提問!

我用這個來代替:

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

nodes()收集送我回<tr>元素,而不是數據。正是我想要的。在這裏找到信息:

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