2017-03-17 41 views
0
$('#save-board-assignees').click(function() 
{ 
    $('#board_assignee_table_wrapper input[type="checkbox"]:checked').each(function(i, td_e) 
    { 
     console.log('Found checked checkbox'); 
     var assignee_id = 0; 
     var team_id = 0; 
     var assignee_holder = []; 

     assignee_id = $(this).closest('td').next().attr('id'); 
     assignee_name = $(this).closest('td').next().html(); 
     team_id = $(this).closest('td').next().next().attr('id'); 

     console.log('Assignee name: ' + assignee_name); 
     console.log('Team id: ' + team_id); 
     console.log('Assignee id: ' + assignee_id); 

     assignee_holder.push(assignee_id, assignee_name); 
     board_assignees.push(assignee_holder); 
    }); 
} 

此代碼僅被選中的頁面上選中的複選框的兄弟<td>(受讓人的名稱,團隊ID,受讓人ID)的值。它不會在DataTable的其他頁面中選中複選框。根據數據表中所有選中的複選框獲取同級td值?

這裏的表結構的示例代碼段: https://jsfiddle.net/30u4knrs/

+0

@KScandrett將這個好起來? https://jsfiddle.net/30u4knrs/1/ – herondale

+0

你在使用http://datatables.net/? –

+0

@KScandrett是的是的 – herondale

回答

0

使用.$()https://datatables.net/reference/api/%24())來訪問所有表元素(不只是那些當前可見的):

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

table 
    .$('input[type="checkbox"]:checked') 
    .each(function(i, td_e) { ... 
+0

沒想到會這麼簡單。謝謝! – herondale

相關問題