I'm looking for call a js function after click on my dropdown list. The code works, when I click it, it call myFunction. My problem is I need to add the datatable row into myFunction as a parameter.
My error: ReferenceError: Can't find variable: meta
I'm noob with javascript and html languages.
<script>
function myFunction(selectObject, row) {
var value = selectObject.value;
alert("Actualización Status: " + value + row);
}
</script>
<script>
var json={{ posts_list | safe }};
$(document).ready(function() {
var table = $('#posts_table').DataTable( {
dom: 'Bfrtip',
buttons: [
'copy', 'csv', 'excel', 'print'
],
"scrollX": true,
data: json.data,
columns:[
{defaultContent: ""},
{data: "_id"},
{
"data": "status",
"render": function(data, type, row, meta){
if (data == 'no_denunciado') {
data = '<select id="status" onchange="myFunction(this, meta.row)">' +
'<option value="no_denunciado">' + data + '</option>' +
'<option value="nuevo">Nuevo</option>' +
'<option value="en_gestion">En Gestion</option>' +
'<option value="baja_edenor">Baja</option>' +
'</select>';
}
metais an argument to therenderfunction. By the timemyFunctionis called, it's out of scope and JavaScript has no idea what you're talking about. I suggest adding elements using DOM methods (i.e.,createElement) and usingaddEventListenerto include the enclosed variable as needed. There may be something easier in DataTables though.