我将 Jquery DataTables 1.7.6 与 JQuery 1.8.6 一起使用。我正在尝试设置一个在一行中有一个按钮的数据表,然后捕获对该按钮的单击以将该行移动到另一个表。我在获取 DataTable 中的数据以调用添加和删除函数时遇到问题。
<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>