私は次のように設定されたテーブルを持っています:
<table id="myTable">
<thead>
<tr>
<td><input type="checkbox" id="selectall" /></td>
<td>Column 1</td>
<td>Column 2</td>
<td>Column 3</td>
<td>Column 4</td>
<td>Column 5</td>
</tr>
</thead>
<tbody>
</tbody>
</table>
次に、JavaScript:
var myTable = jQuery('#myTable').dataTable({
/* options */
});
// Ajax request to populate:
jQuery.get('script.php', function(data){
eval("rows="+data);
for(var i=0;i<rows.length;i++){
myTable.fnAddData([
"<input type=\"checkbox\" id=\""+rows[i].uniqueID+"\" />",
rows[i].col1Txt,
rows[i].col2Txt,
rows[i].col3Txt,
rows[i].col4Txt,
rows[i].col5Txt ]);
}
});
現在、どのチェックボックスが選択されているかに基づいてテーブルを更新するのに問題があります。
チェックされている各行の 5 番目のセルを更新しようとしています。fnUpdate
とfnGetPosition
( http://www.datatables.net/api )の組み合わせを使用しています。
fnGetPosition
td
または要素が必要tr
なので、チェックボックスの親を取得するだけだと思いましたtd
:
var checkBoxes = jQuery('td > input:checked', myTable);
for(var i=0;i<checkBoxes.length;i++){
var parentTD = jQuery('#'+checkBoxes[i].id).parent(); //seems wrong?
var pos = myTable.fnGetPosition(parentTD);
//alert(pos[0]);
myTable.fnUpdate('Updated text', pos[0], 5);
}
しかし、値を保持していないように見えるparentTD
ので、私は間違っているに違いありません。pos
何か案は?