jquery数据表在重绘后无法选择行

bvn*_*ati 5 jquery datatables

我正在使用jquery datatable插件在jquery UI对话框中显示一个表.下面是我打电话来绘制表格的函数.

function listPtCharges(filter){
var chgTable;
chgTable =
  $('#chargeTable').dataTable({
    "bJQueryUI": true,
    "bDestroy": true,    
    "sDom": 'tT',
    "bSort": false,
    "bAutoWidth": false,
    "sAjaxSource": "/ajax/ptchglist.php",
    "sAjaxDataProp": "Records",
    "fnServerData": function ( sSource, aoData, fnCallback ) {
      aoData.push( { "name": "acctno", "value": $("#curAcctno").val() } );
      aoData.push( { "name": "ins_id", "value": $("#ins_id").val() } );
      aoData.push( { "name": "filter", "value": filter } );
      $.ajax( {
        "dataType" : 'json',
        "type" : "POST",
        "url" : sSource,
        "data" : aoData,
        "success" : fnCallback
        } );
    } ,
    "aoColumns":
    [
     {"bVisible":false},
     {"sWidth": 55},
     {"sWidth": 30},
     {"sWidth": 40},
     {"sWidth": 125},
     {"sWidth": 50},
     {"sWidth": 50},
     {"sWidth": 20},                
     {"bVisible":false}  // allowed
    ],
    "oTableTools": {
      "sRowSelect": chgSelctionTyp,
      "sSwfPath": "/swf/copy_csv_xls_pdf.swf",
      "aButtons": []
    }
  });
}
Run Code Online (Sandbox Code Playgroud)

在调用open对话框之后调用此函数.以下是打开对话框然后加载表的代码行.

var oTT = TableTools.fnGetInstance( 'chargeTable' );
      if(oTT)
        oTT.fnSelectNone();
      $( "#chargeList" ).dialog( "open" );
      listPtCharges();
Run Code Online (Sandbox Code Playgroud)

在对话框中,我有另一个按钮,带有过滤器值的事件处理程序,并使用新过滤器调用相同的函数.新加载的表总是从服务器带来更多行.

除了一个奇怪的问题,一切都很好.每当绘制具有更多行的新表时,只能选择与前一个表相等的行数.

我的意思是假设我加载了5行的表格,按下按钮为表格带来新的数据集.表加载了8行.但现在我只能选择前5行.休息全部将导致与不明身份相关的萤火虫出错.

在这方面的任何帮助都非常值得注意.

编辑: 这是尝试访问所选行的代码.

    var oTT = TableTools.fnGetInstance( 'chargeTable' );
    var aData = oTT.fnGetSelectedData();
Run Code Online (Sandbox Code Playgroud)

这也是jquery数据表的一部分,它在firebug中显示错误.

"fnIsSelected": function ( n )
{
var pos = this.s.dt.oInstance.fnGetPosition( n );
return (this.s.dt.aoData[pos]._DTTT_selected===true) ? true : false;
}, 
Run Code Online (Sandbox Code Playgroud)

单击不可单击的行后,将显示以下错误.

TypeError:this.s.dt.aoData [pos]未定义

我猜aodata的长度在某种程度上仍然与之前加载的表相同.

LeG*_*GEC 4

您不应该销毁并重建表,您应该让数据表重新获取数据。

我认为调用fnDraw足以触发刷新 - 但尚未测试:

 $('#chargeTable').dataTable().fnDraw();
Run Code Online (Sandbox Code Playgroud)

在您的fnServerData函数中,您可能需要更改加载参数的方式filter

// keep this variable in some shared scope :
var filterPtr = {value: ''};

$('#chargeTable').dataTable({
    ....
    "fnServerData": function(...){
         ...
         aoData.push({ "name": "filter", "value": filterPtr.value });
         ...
     }
});

// if you need to update the filter :
filterPtr.value = 'newValue';
$('#chargeTable').dataTable().fnDraw();
Run Code Online (Sandbox Code Playgroud)