2012-02-03 73 views
1

我在安装jEditable插件时使用jQuery DataTables。我有一切正常工作,表格呈现并正确拉取数据。该表是可编辑的,脚本正确更新后端数据库。唯一的问题是值得到更新,然后单元格为空,直到你刷新,然后新的值是可见的。jEditable&DataTables - 表格不会在更新时刷新

我试图将fnDraw并入回调,以便它会重绘表,但我无法弄清楚它?我唯一缺少的就是在将新值写入数据库之后动态刷新表。

这里是我的代码:

<script> 
$(document).ready(function() { 
/* Init DataTables */ 
var oTable = $('#district').dataTable(); 

/* Apply the jEditable handlers to the table */ 
$('#district', oTable.fnGetNodes()).editable('lib/editable_ajax.php', { 
    tooltip : 'Click cell to edit value...', 
    indicator : 'Saving...', 
    style : 'display:block;', 
    submit : 'OK', 
    cancel : 'Cancel', 
    data : " {'PDC 30':'PDC 30','PDC 14':'PDC 14','PDC 81':'PDC 81','PDC 58':'PDC 58'}", 
    type : 'select', 
    "Callback": function(sValue, x) { 
     var aPos = oTable.fnGetPosition(this); 
     oTable.fnUpdate(sValue, aPos[0], aPos[1]); 

     /* Redraw the table from the new data on the server */ 
     oTable.fnClearTable(0); 
     oTable.fnDraw(); 
    }, 
    "submitdata": function (value, settings) { 
     var aPos2 = oTable.fnGetPosition(this); 
     var id2 = oTable.fnGetData(aPos2[0]); 
     return { 
      "row_id": this.parentNode.getAttribute('id'), 
      "id2": id2[0], 
      "column": oTable.fnGetPosition(this)[ 2 ]   
     }; 
    }, 
    "height": "14px", 
}); 
}); 
</script> 

回答

0

尝试初始化变量oTable功能外,看到,尽管这不应该使任何区别为你的代码看起来不错。