Changing parameters for datatable loaded with fnserverdata

Changing parameters for datatable loaded with fnserverdata

ZedZimZedZim Posts: 1Questions: 1Answers: 0

I'm using the following function to load a DataTables table with data from the server. I would like to reload the table with different parameters on a click event only i cant work out how to do this. If i call reload it just reloads with the original parameters if i reinitialise the whole table it throws an error as the table already exists.

I have been looking into fnServerParams but cant work out if it would help or not.

If anyone can point me in the correct direction that would be great.

function LoadRiskProfileModalTable(userId, teamId, riskProfileClass) {

var params = {
    userId: userId,
    teamId: teamId,
    riskProfileClass: riskProfileClass
};

var data = JSON.stringify(params);
//if (!$.fn.DataTable.isDataTable("#riskProfileTable")) {

    var table = $("#riskProfileTable").DataTable({
        "bProcessing": true,
        "sAjaxSource": "WFMHome.aspx/GetRiskProfileDrillThroughDatatable",
        "fnServerData": function (sSource, aoData, fnCallback) {
            //aoData.push(JSON.stringify(params));
            $.ajax({
                "dataType": 'json',
                "contentType": "application/json; charset=utf-8",
                "type": "POST",
                "url": sSource,
                "data": data,
                "success": function (msg) {
                    var json = jQuery.parseJSON(msg.d);
                    fnCallback(json);
                    $("#riskProfileTable").show("fast", function () { $('#riskProfileTableLoading').hide("fast") });
                },
                error: function (xhr, textStatus, error) {
                    if (typeof console == "object") {
                        appendAlert("errorAlertPlaceholder", xhr.responseText, 1, "danger");
                        console.log(xhr.status + "," + xhr.responseText + "," + textStatus + "," + error);
                    }
                }
            });
        },
        "columns": [
            { "data": "CaseHandler" },
            { "data": "caseAreaText" },
            { "data": "RiskProfileText" },
            { "data": "PassChecks" },
            { "data": "F1Checks" },
            { "data": "F2Checks" },
            { "data": "F3Checks" },
            { "data": "CurrentChecks" }
        ]
    });
//} 
//else {
//        $('#riskProfileTable').DataTable().ajax.reload();
//    }
};

Answers

This discussion has been closed.