我在JQuery 1.8.6中使用Jquery DataTables 1.7.6。我試圖設置一個數據表,在一行中有一個按鈕,然後捕獲該按鈕的點擊以將該行移動到另一個表。我在獲取DataTable中的數據時遇到問題以調用add和remove函數。通過點擊綁定訪問數據表數據
<script type="text/javascript">
$(document).ready(function() {
var eligibleCreatives = $('#EligibleCreativeTableId').dataTable({
"bJQueryUI": true,
"bStateSave": true,
"bAutoWidth": false,
"aoColumnDefs": [
{ "bSortable": false, "aTargets": [0] },
{ "bVisible": false, "aTargets": [3] },
],
"aaSorting": [[1, "asc"]]
});
associatedCreatives = $('#AssociatedCreativeTableId').dataTable({
"bJQueryUI": true,
"bStateSave": true,
"bAutoWidth": false,
"aoColumnDefs": [
{ "bSortable": false, "aTargets": [0] },
{ "bVisible": false, "aTargets": [3] },
],
"aaSorting": [[1, "asc"]]
});
eligibleCreatives.$('tr').click(function() {
var data = .fnGetData(this);
// this tells me that eligibleCreatives has no method $
});
$('#disassociate-creative').click(function() {
//I can't get at the actual row node here.
var data = associatedCreatives.fnGetData($(this).closest('tr')[0]);
eligibleCreatives.fnAddData(data);
associatedCreatives.fnDeleteRow(this);
return false;
});
$('#associate-creative').click(function() {
var data = associatedCreatives.fnGetData($(this).closest('tr')[0]);
associatedCreatives.fnAddData(data);
eligibleCreatives.fnDeleteRow(this);
return false;
});
});
function fnClickAssociate() {
$('#AssociatedCreativeTableId').dataTable().fnDeleteRow();
$('#AssociatedCreativeTableId').dataTable().fnAddData([]);
}
</script>