fnreloadajax

fnreloadajax

firozpjmuhammadfirozpjmuhammad Posts: 5Questions: 1Answers: 0

iam using server side processing script and i want to change data in a button click so use fnreload ajax.but one problem it showing pagination part as

"Showing 1 to NaN of NaN entries (filtered from NaN total entries) First Previous 1 2 3 4 5 Next Last"

but it contain only two data. how i solve this problem?

This question has an accepted answers - jump to answer

Answers

  • algeealgee Posts: 11Questions: 2Answers: 0

    seems your serverside script doesn't provide the array fields "recordsFiltered" & "recordsTotal" within the reply, thus dt can not process the pagination properly.

    without further insight into your code, will be hard to figure out what's wrong :S

  • firozpjmuhammadfirozpjmuhammad Posts: 5Questions: 1Answers: 0
    edited April 2016

    fnreloadajax url return
    $sec=array(
    array("name", "company", "doj", "email", "phone"),
    array("name", "company", "doj", "email", "phone")
    );
    return json_encode(array("aaData" => $sec));

    and if modify response like,

    $output = array(
    'sEcho' => intval($sEcho),
    'iTotalRecords' => $iTotal,
    'iTotalDisplayRecords' => $iFilteredTotal,
    'aaData' => $sec
    );
    return json_encode($output);

    then a popup message show like json format error

  • allanallan Posts: 61,880Questions: 1Answers: 10,139 Site admin
    Answer ✓

    If you are getting a JSON error, did you follow the instructions in the tech note that the error links to? What is the return from the server, since it isn't valid JSON?

    Also, note that you are returning legacy parameters (sEcho etc) rather than the current parameters. Without a test case, I can't say if that is intentional or not.

    Allan

  • firozpjmuhammadfirozpjmuhammad Posts: 5Questions: 1Answers: 0
    edited April 2016

    fnreloadajax code is like,

    jQuery.fn.dataTableExt.oApi.fnReloadAjax = function (oSettings, sNewSource, fnCallback, bStandingRedraw)
    {
    // DataTables 1.10 compatibility - if 1.10 then versionCheck exists.
    // 1.10's API has ajax reloading built in, so we use those abilities
    // directly.
    if (jQuery.fn.dataTable.versionCheck) {
    var api = new jQuery.fn.dataTable.Api(oSettings);

        if (sNewSource) {
            api.ajax.url(sNewSource).load(fnCallback, !bStandingRedraw);
        } else {
            api.ajax.reload(fnCallback, !bStandingRedraw);
        }
        return;
    }
    
    if (sNewSource !== undefined && sNewSource !== null) {
        this.fnClearTable(this);
        oSettings.sAjaxSource = sNewSource;
        this.dataTable().fnClearTable();
        oSettings.iDraw = 0;
        this.dataTable().fnDraw();
    }
    
    // Server-side processing should just call fnDraw if (oSettings.oFeatures.bServerSide) {
        this.fnDraw();
        return;
    }
    
    this.oApi._fnProcessingDisplay(oSettings, true);
    var that = this;
    var iStart = oSettings._iDisplayStart;
    var aData = [];
    
    this.oApi._fnServerParams(oSettings, aData);
     /*       Extra added */
    this.dataTable().fnClearTable();
    oSettings.iDraw = 0;
    this.dataTable().fnDraw();
    /* extra added close */
    oSettings.fnServerData.call(oSettings.oInstance, oSettings.sAjaxSource, aData, 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 < aData.length; i++)
        {
            that.oApi._fnAddData(oSettings, aData[i]);
        }
    
        oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
    
        that.fnDraw();
    
        if (bStandingRedraw === true)
        {
            oSettings._iDisplayStart = iStart;
            that.oApi._fnCalculateEnd(oSettings);
            that.fnDraw(false);
        }
    
        that.oApi._fnProcessingDisplay(oSettings, false);
    
        /* Callback user function - for event handlers etc */
        if (typeof fnCallback == 'function' && fnCallback !== null)
        {
            fnCallback(oSettings);
        }
    }, oSettings);
    

    };

    modify response like,
    $output = array(
    'sEcho' => intval($sEcho),
    'iTotalRecords' => $iTotal,
    'iTotalDisplayRecords' => $iFilteredTotal,
    'aaData' => $sec
    );
    return json_encode($output);

    now datatable not refresh table with new data it show old data.

    josn format is like,
    {sEcho: 1, iTotalRecords: 15, iTotalDisplayRecords: 10,…}
    aaData:[["testtteeeeee", "EMP201610065", "04/06/2016", "firoz@gmail.com", "455455454"],…]

    0:["testtteeeeee", "EMP201610065", "04/06/2016", "firozpjmuha@gmail.com", "455455454"]

    1:["testttest", "EMP201610060", "04/05/2016", "firozpjm@gmail.com", "555555"]

    2:["testtesttest", "EMP201610064", "04/05/2016", "5343434", "54333353"]

    3:["test testtest", "EMP201610062", "04/05/2016", "firozpj@gmail.com", "5224244"]

    4:["testfftest", "EMP201610061", "04/05/2016", "firozpjmuhammad@gmail.com","54545454"]

    5:["TESTEE", "EMP20161009", "03/09/2016", "te@ff.gg", "5433535353"]

    6:["serinawillamsw", "EMP201610070", "04/07/2016", "we@gmail.com", "1234567890"]

    7:["ramut ramu", "EMP201610010", "04/05/2016","firozpjmuhammad@gmail.com","44444"]

    8:["kgfjhjhjhjgmnhmn", "EMP201610068", "04/06/2016","firozpjxz@gmail.com", "4545565656"]

    9:["fdsfsfdfsfsffdsfsfsf", "EMP201610066", "04/05/2016", "dfsfsfsfs", "dfsffsf"]

    10:["Elbin123sssss", "EMP201610069", "04/01/2016", "elb@gmail.com", "1234567890"]

    iTotalDisplayRecords:10
    iTotalRecords:15
    sEcho:1

  • allanallan Posts: 61,880Questions: 1Answers: 10,139 Site admin

    Can you link to the page so I can debug it please.

  • firozpjmuhammadfirozpjmuhammad Posts: 5Questions: 1Answers: 0

    clear all errors and one problem fnreloadajax pass 4 request in a single button click.in that one requet is "sAjaxSource" url. how can solve this?

  • allanallan Posts: 61,880Questions: 1Answers: 10,139 Site admin

    As above, please link to a test case. Also, ajax.reload() is the built in function that provides this ability in 1.10+.

This discussion has been closed.