jQuery数据表刷新数据不工作

jQuery数据表刷新数据不工作,jquery,jquery-datatables,Jquery,Jquery Datatables,我可以使用服务器端填充数据表和其他工作表,但单击reload_table元素后无法刷新数据。清除数据表工作正常,但绘图不工作 JQUERY: $('#reload_table').live('click',function(){ oTable_topics.fnReloadAjax(oTable_topics.fnSettings()); oTable_topics.fnClearTable(); oTable_topics.fnDraw(); $.ajax({

我可以使用服务器端填充数据表和其他工作表,但单击
reload_table
元素后无法刷新数据。清除数据表工作正常,但绘图不工作

JQUERY:

$('#reload_table').live('click',function(){
   oTable_topics.fnReloadAjax(oTable_topics.fnSettings());
   oTable_topics.fnClearTable();
   oTable_topics.fnDraw();
    $.ajax({
       url: "server_processing.php",
       success: function() {
           // if it worked, ask datatable to redraw the table with the new data
           $("#showTopics").dataTable().fnDraw();
           // if this js function does anything useful (like deleting the row), then call it:
           Success();
       },
       error: function() {
           // display any error (like server couldn't be reached...), or at least try to log it
       }
    });
});
oTable_topics =$('#showTopics').dataTable({
        "bLengthChange": false,
        "iDisplayLength": 12,                               
        "bScrollCollapse": true,       
        "bJQueryUI": true,
        "bAutoWidth": false,
        "sAjaxSource": "server_processing.php",
        "sPaginationType": "full_numbers",
        "bProcessing": true,

        "fnDrawCallback": function(oSettings) {
            clickRowHandler_topics();
            if ( oSettings.aiDisplay.length == 0 )
            {
                return;
            }                       
            var nTrs = $('tbody tr', oSettings.nTable);
            var iColspan = nTrs[0].getElementsByTagName('td').length;
            var sLastGroup = "";
            for ( var i=0 ; i<nTrs.length ; i++ )
            {
                var iDisplayIndex = oSettings._iDisplayStart + i;
                var sGroup = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex] ]._aData[0];
                if ( sGroup != sLastGroup )
                {
                    var nGroup = document.createElement( 'tr' );
                    var nCell = document.createElement( 'td' );
                    nCell.colSpan = iColspan;
                    nCell.className = "group";
                    nCell.innerHTML = sGroup;
                    nGroup.appendChild( nCell );
                    nTrs[i].parentNode.insertBefore( nGroup, nTrs[i] );
                    sLastGroup = sGroup;
                }
            }
        },
        "aoColumnDefs": [
            { "bVisible": false, "aTargets": [ 0 ] }
        ],
        "aaSortingFixed": [[ 0, 'asc' ]],
        "aaSorting": [[ 1, 'asc' ]],
        "fnServerParams": function ( aoData ) {
          aoData.push(
             {"name": "id"   ,      "value": "i.id" },          
             {"name": "subject"   , "value": "i.subject" },
             {"name": "date_time",  "value": "i.date_time"} ,
             {"name": "posted_by",  "value": "u.username"} ,
             {"name": "ctitle"   ,  "value": "c.title"} ,
             {"name": "etitle"   ,  "value": "e.title"},
             {"name": "istatus"   ,  "value": "i.status"},
             {"name": "join"     ,  "value": "JOIN categories c ON i.category = c.id JOIN status_topics e ON i.status = e.id JOIN users u ON i.posted_by = c.id"},
             {"name": "action"   ,  "value": "topics" }
          )}
        });
$('reload#u table').live('click',function()){
oTable_topics.fnReloadAjax(oTable_topics.fnSettings());
oTable_topics.fnClearTable();
oTable_topics.fnDraw();
$.ajax({
url:“server_processing.php”,
成功:函数(){
//如果有效,请datatable使用新数据重新绘制该表
$(“#显示主题”).dataTable().fnDraw();
//如果此js函数执行任何有用的操作(如删除行),请调用它:
成功();
},
错误:函数(){
//显示任何错误(如无法访问服务器…),或者至少尝试记录它
}
});
});
oTable_topics=$('#showTopics')。数据表({
“bLengthChange”:false,
“iDisplayLength”:12,
“崩溃”:没错,
“bJQueryUI”:没错,
“bAutoWidth”:假,
“sAjaxSource”:“server_processing.php”,
“sPaginationType”:“完整编号”,
“bProcessing”:正确,
“fnDrawCallback”:函数(oSettings){
单击RowHandler_主题();
if(oSettings.aiDisplay.length==0)
{
返回;
}                       
var nTrs=$('tbody tr',oSettings.nTable);
var iColspan=nTrs[0]。getElementsByTagName('td')。长度;
var sLastGroup=“”;

对于(var i=0;i我一直在使用fnReloadAjax加载新数据,而fnLengthChange在加载时更改页面长度

oTable.fnClearTable(0);
oTable.fnReloadAjax('/' + myLocation + '/' + myCustomerId);
oTable.fnLengthChange(pageLength);

.live已被弃用。请使用on@SamithaHewawasam是的,但我的问题是重新绘制表格。mahdi,也许你也应该试着问一下Allan的fnReloadAjax说“默认情况下,DataTables仅在初始化时使用sAjaxSource变量,但是重新读取Ajax源代码并更新表可能会很有用。通常,您需要使用fnClearTable()和fnAddData()函数,但这会将其全部封装在一个函数调用中。“他的示例只显示了调用fnReloadAjax。我认为您不需要调用fnClearTable。