I'm trying to figure out how to pass data from an AJAX Datatable column, which is an array, to a JavaScript function.
Below is my script.js:
table = $("#table").DataTable({
ajax: {
url: "/Object/GetAllDetail",
data: { },
type: 'POST',
datatype: "json",
dataSrc: "",
dataFilter: function (data) {
var json = jQuery.parseJSON(data);
json.recordsTotal = json.TotalCount;
json.recordsFiltered = json.TotalCount;
json.data = json.list;
return JSON.stringify(json); // return JSON string
},
},
"columns": [
{
"data": null,
"className": "checkbox",
"render": function (data, type, full, meta) {
var ACT = '<div class="form-check">';
ACT += '<input type="checkbox" name="CheckBoxDatatbl" onclick="Display(' + data.text + ',' + data.ArrayNum + ')" + ' >';
ACT += '</div >';
return ACT;
}
}]
}
function Display(text, array){
return text + " : " + array;
}
In the example below:
data.text = "First Row";
data.ArrayNum = [1,3,5];
The issue lies in how AJAX converts the data.ArrayNum to arrays before sending them to the function. This results in the following output:
<input type="checkbox" name="CheckBoxDatatbl" **onclick="Sum("First Row",1,3,5)"** >
As a result, only the Display("First Row",1) portion is recognized by the Display() function, not the entire array.
Any ideas on how I can concatenate all elements of the array within the function?