在数据表中使用fnReloadAjax

时间:2011-10-15 09:14:02

标签: jquery client datatables

我使用以下代码来触发服务器:

$.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback, bStandingRedraw )
        {
            if ( typeof sNewSource != 'undefined' && sNewSource != null )
            {
                oSettings.sAjaxSource = sNewSource;
            }
            this.oApi._fnProcessingDisplay( oSettings, true );
            var that = this;
            var iStart = oSettings._iDisplayStart;

            oSettings.fnServerData( oSettings.sAjaxSource, [], function(json) {
                /* Clear the old information from the table */
                that.oApi._fnClearTable( oSettings );

                /* Got the data - add it to the table */
                var aData =  (oSettings.sAjaxDataProp !== "") ?
                    that.oApi._fnGetObjectDataFn( oSettings.sAjaxDataProp )( json ) : json;

                for ( var i=0 ; i<json.aaData.length ; i++ )
                {
                    that.oApi._fnAddData( oSettings, json.aaData[i] );
                }

                oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
                that.fnDraw();

                if ( typeof bStandingRedraw != 'undefined' && bStandingRedraw === true )
                {
                    oSettings._iDisplayStart = iStart;
                    that.fnDraw( false );
                }

                that.oApi._fnProcessingDisplay( oSettings, false );

                /* Callback user function - for event handlers etc */
                if ( typeof fnCallback == 'function' && fnCallback != null )
                {
                    fnCallback( oSettings );
                }
            }, oSettings );
        }

但是,这不会传递GET参数。我希望那些与它一起传递。请指导我完成这个。在过去的几个小时里,我一直在为此工作和冲浪。

提前致谢。

1 个答案:

答案 0 :(得分:6)

当我调用fnReloadAjax时,我将GET参数放在第一个函数参数中,如下所示:

//table declaration
var mainTable = $("#mainTable").dataTable({ 
    "sAjaxSource": "tableParams.php?"+getParams
    //other table parameters
})

//table reload
function reloadMainTable(){
    mainTable.fnReloadAjax("tableParams.php?"+getParams);
}

其中变量getParams类似于:

var getParams = "foo=bar&user=myself&date=20-04-2012";

是你想要的吗?