Undefined Values Using Jquery Datatable
Solution 1:
You have to define data
as null
(I believe you not want the button to be placed in the note
column) :
...
{ "data": "note" },
{ "data": null,
"render": function ( data, type, full, meta ) {
return"<button type='button' class='btn btn-info btn-md' data-toggle='modal' data-id=\'" + full.id + "\' data-target='#myModal'> Edit </button>";
}
}
and address full
instead of data
, i.e. data-id=\'" + full.id + "\'
$(this).data('id');
is wrong. It is jQuerys own invention of storing variables on an element. Unless you have added data-id
with data()
specifically you cannot retrieve it with data()
. Use $(this).attr('data-id')
instead.
Solution 2:
Solved by myself. Speaking with a colleague, we suppose that, cause the modal has his activation button code on a file as string and the rest of code into another, this may take some problems. We don't know if thies hypotesis is correct, but starting from this assumption we formulate this solution:
- we put a global variable
id_event
at the start of code; in the render function, set this variable with the data.id value, without using the data-id field in the modal button, by onclick in the button:
{ "data": null, "render": function ( data, type, full, meta ) {
return "<buttontype='button'class='btn btn-info btn-md'data-toggle='modal'data-target='#myModal'onclick=\'id_event="+data.id+"\'> Edit </button>"; }
In the ajax function for sending data to Controller, set with IDnumber the formdata.idevent field:
formdata.idevent = id_event; //add the event id to form data, after setting it with the IDnumber variabile
This made our code perfectly working.
Post a Comment for "Undefined Values Using Jquery Datatable"