2017-02-09 77 views
0

我正在使用DataTables 我想選擇我的表的第一行並將「DTTT_selected」類添加到第一行。JQuery DataTables將類添加到initComplete中的第一行

我已經成功地選擇第一行,但是當我添加類它增加了「DTTT_selected」的所有行,而不是選擇的第一行。

的代碼是: -

table = $('#resultTable').DataTable({ 
aaSorting: [], 
ajax: {...}, 
columnDefs: [...], 
initComplete: function() { 
    console.log('DataTables has finished its initialisation.'); 
    var api = this.api(); 
    var CurrentRow = api.row({ order: 'current' }, 0); 
    CurrentRow.select(); //Working Fine 
    CurrentRow.$('tr').addClass('DTTT_selected'); // Results all Rows get class DTTT_selected 
    } 
    } 
}); 

可有一個人幫我,我怎麼能做到這一點?

謝謝。

+0

試試這個CurrentRow $( 'TR:當量(0)')。addClass( 'DTTT_selected'); –

回答

2

嘗試

CurrentRow.$('tr:first').addClass('DTTT_selected'); 
相關問題