how can I pass multiple parameter to the function
how can I pass multiple parameter to the function
polachan
Posts: 101Questions: 50Answers: 0
Hi
I have given my code given below. I want to pass ID,EmployeeName,ClockedDatetoListas argument to the function from the clicked event of button . ShowDeleteModalPopup. Please can you help me with suggested code
var table= $('#tblData').DataTable({
"ajax": {
"url": "/Home/GetClockList?employeeid=" + $('#dropdownEmployee').val()
+ "&clockdate=" + $('#txtAttendanceDate').val() ,
"type": "GET",
"datatype": "json",
"dataSrc": function (json) {
return JSON.parse(json);
}
},
"columns": [
{ "data": 'ID', "width": "6%" },
{ "data": 'EmployeeName', "width": "20%" },
{ "data": 'ClockedDatetoList', "width": "20%" },
{
"data": "ID",
"render": function (data) {
return `<div class="text-center">
<a class='btn btn-danger text-white' style='cursor:pointer; width:100px;' onclick="ShowDeleteModalPopup(${data})" >
<i class='far fa-trash-alt'></i> Delete
</a></div>
`;
}, "width": "5%"
}
],
function ShowDeleteModalPopup()
alert(id);
$('#lblID').val(id);
$('#deleteConfirmationModal').modal('show');
}
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This discussion has been closed.
Answers
Here are a couple options you can try.
This uses
columns.render
:http://live.datatables.net/qemodapi/1/edit
This uses
columns.defaultContent
:http://live.datatables.net/xijecupo/1/edit
Kevin
Please can you help me how to bring the values ID and EmployeeName to the function ShowDeleteModalPopup()
Please post a running example of what you have so we can take a look at what happens. This will allow us to offer suggestions.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
If you use one of the examples I provided you will be able to easily get the row data which you can pass into your function.
Kevin
I have the same issue and I found the solution from SO. Hope it helps the people in the future.
https://stackoverflow.com/questions/67380020/how-to-pass-multiple-parameters-in-columns-render-function-in-datatables-jquery