Hi there.
I have a table set out like:
<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>
Then, the 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 ]);
}
});
Now, I am having trouble with updating the table based on which checkboxes are selected:
I am trying to update the 5th cell in each row that is checked. I am using a combination of fnUpdate
and fnGetPosition
(http://www.datatables.net/api).
fnGetPosition
expects the td
or tr
element, so I thought I'd just grab the parent td
of the checkboxes:
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);
}
But I must be doing parentTD
wrong since pos
never seems to hold a value.
Any ideas?