How to get parameter from another datatable column?

How to get parameter from another datatable column?

mastersusemastersuse Posts: 61Questions: 28Answers: 0

My objective is to carry multiple parameters in same row but from different column. In my case, each row contain of 7 columns. but only 3 parameters that I need to pass to btnApprove1 function. This function will appoint to other API which require all that 3 parameters.

So how to carry service_id, project_id and staff_id into btnApprove function when clicked?

columns: [
    { data : "service_id", "className": "text-center" },
    { data : "project_id", "className": "text-center" },
    { data : "staff_id", "className": "text-center" },
    { data : "status", "className": "text-center",
        render: function(data){
            if (data == "1001") {
                return  "<span onclick='btnApprove(&quot;"+data+"&quot;)'</span>";
            }
            else {
                return data;
            }
        }
    },
    { data : "lorry", "className": "text-center" },
    { data : "car", "className": "text-center" },
    { data : "van", "className": "text-center" }
]

function btnApprove(service_id, project_id, staff_id){

    console.log(service_id, project_id, staff_id)

    var params = {
        "service_id": service_id,
        "project_id": project_id,
        "staff_id": staff_id
    };

    params = JSON.stringify(params);

    $.ajax ({
        ...
    });

}

Answers

  • mastersusemastersuse Posts: 61Questions: 28Answers: 0
    edited July 2020

    I just solve this issue.

    { data : "status", "className": "text-center",
        fnCreatedCell: function (nTd, sData, oData, iRow, iCol) {
            if (oData.status == "1001") {
                var stat = '<span class="badge badge-warning font-11">Approval</span><br/>';
                $(nTd).html("<span onclick='btnApprove(&quot;"+oData.service_id+"&quot;, &quot;"+oData.project_id+"&quot;, &quot;"+oData.staff_id+"&quot;)'>"+stat+"</span>");
            }
            else if (oData.status == "1000") {
                var stat2 = '<span class="badge badge-primary font-11">Registered</span>';
                $(nTd).html("<span onclick='btnApprove(&quot;"+oData.service_id+"&quot;, &quot;"+oData.project_id+"&quot;, &quot;"+oData.staff_id+"&quot;)'>"+stat2+"</span>");
            }
        }
    },
    
This discussion has been closed.