以下の例では、強調表示は個々の行で非常にうまく機能します。私のコードでは、個々の行の選択が機能していることがわかりますが、実際の強調表示は機能しません。
Twitter Bootstrap 3 + Datatables を使用しています。
http://datatables.net/release-datatables/examples/api/select_single_row.html
どんな助けでも大歓迎です。私はそのまま例に従いましたが、おそらく初期化でテーブルを適切に構成していないか、Bootstrap が強調表示をあまり好きではないと思います。
var oTable;
$( document ).ready(function() {
/* Add a click handler to the rows - this could be used as a callback */
$("#pTable tbody tr").click( function( e ) {
if ( $(this).hasClass('row_selected') ) {
$(this).removeClass('row_selected');
}
else {
oTable.$('tr.row_selected').removeClass('row_selected');
$(this).addClass('row_selected');
}
});
/* Add a click handler for the delete row */
$('#deletePButton').click( function() {
var anSelected = fnGetSelected( oTable );
if ( anSelected.length !== 0 ) {
oTable.fnDeleteRow( anSelected[0] );
}
});
/* Init the table */
oTable = $('#pTable').dataTable( );
/* Get the rows which are currently selected */
function fnGetSelected( oTableLocal )
{
return oTableLocal.$('tr.row_selected');
}
});
したがって、行を選択して行を削除すると、コードで参照されている deleteButton が機能します。ハイライトだけじゃダメ!