2012-12-22 54 views
1

我有我的客戶dataTable有五列。一列包含超鏈接。其中一列是複選框。 我想要當用戶點擊行時,該行應該被選中(這意味着行顏色應該改變,並應該選擇複選框 )。我可以用下面的代碼片段做到這一點行選擇行點擊,但沒有超鏈接點擊jQuery數據表中的列之一?

$("#customer").on('click', $.fn.getDataTablesClickHandler("#selectAll")); 
//where customer is the html div associated with dataTable and call the same function which gets triggered 
//on call of selectAll html element. Inside that function i toggle the class of row 

它很好用。但我的問題是我不希望發生這種情況(即行看)在一個列內的鏈接點擊。 我怎麼能做到這一點?所以基本上我怎麼能限制發射getDataTablesClickHandler點擊單元格中的某個鏈接或點擊單元格上的

回答

2

試試這個,你想看看哪個目標被點擊,如果它是一個錨標籤,就忽略它。

$("#customer").on('click', function(event) { 
    if(event.target.tagName == 'A') 
     return; 

    $.fn.getDataTablesClickHandler("#selectAll").apply(this); 
}); 
+0

Bryan您的解決方案的最後一行$ .fn.getDataTablesClickHandler(「#selectAll」)。apply(this)does not select the row? –

+0

您需要提供一個HTML示例,以便爲您提供更好的答案,我只是簡單地將它應用到#customer作爲tr的上下文中。您可能能夠擺脫.apply(this) – Bryan

1

你可以做這樣的事情:

如果客戶是你的表;

$("#customer").on('click', 'tr', function(){ 
    if(!$(this).is('tr')) 
     return; 
    $.fn.getDataTablesClickHandler("#selectAll"); 
}); 
+0

Anil您的最後一行$ .fn.getDataTablesClickHandler(「#selectAll」)不起作用?我的意思是它不選擇行 –

+0

這完全沒有工作:( – Brainfeeder