私はDatatableを使用していますが、Select()拡張を実装しています。ユーザーがkeyupとkeydownでテーブルをナビゲートできるようにする関数を実装したいのですが、私はそれをどうやって行うことができるのか分かりません。 は、私はこれを試してみましたが、唯一の仕事を削除:DataTable keydownを使用した内線/ナビゲーションの選択
$('#example tbody').on('click', 'tr', function() {
var tr = $(this);
if ($(this).hasClass('selected')) {
$(this).removeClass('selected');
}
else {
table.$('tr.selected').removeClass('selected');
$(this).addClass('selected');
}
//on keypress within tr
$(document).keydown(function(e) {
var tabla = document.getElementById("example");
var fila = tabla.getElementsByClassName('odd selected');
var fila2 = tabla.getElementsByClassName('even selected');
if (e.keyCode == 40){ //arrow down
tr.next().addClass('selected');
table.$('tr.selected').removeClass('selected');
}
if (e.keyCode == 38){ //arrow up
tr.prev().addClass('selected');
table.$('tr.selected').removeClass('selected');
}
})
});
誰も私を助けることができますか?
EDIT:これは私のHTML
<button id="addRow">Insertar fila</button>
<button id="saveData">Guardar datos</button>
<div id="dynamic">
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered table-condensed" width="100%" id="example">
<thead>
<tr>
<th width="10%">NIF/NIE</th>
<th width="10%">1er Apellido</th>
<th width="10%">2do Apellido</th>
<th width="10%">Nombre</th>
<th width="10%">Sexo</th>
<th width="10%">Fecha Nacimiento</th>
<th width="10%">Fecha Contrato</th>
<th width="10%">Demandante empleo larga duración</th>
<th width="10%">Tipo Contrato</th>
<th width="10%">% Jornada</th>
<th width="10%">Discap.</th>
<th width="10%">Causas Archivo. (1)</th>
<th width="10%">Aut. SCSP</th>
<th width="10%">Imp.Solic.</th>
<th width="10%">Sust.</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
ある行は削除してselected
クラスを追加するので、私はアヤックス
あなたのHTMLをまた –