I have a jQuery Data Table with this variable:
"columns": [
{ "data": "id" },
{ "data": "date" },
{ "data": "type" },
{ "data": "name" },
{ "data": "user_name" },
{ "data": "status" },
{ "data": "closing_date" },
{ "data": "info" },
{ "data": "note" },
{ "render": function () {
return "<button type='button' class='btn btn-info btn-md' data-toggle='modal' data-id=\""+data.id+"\" data-target='#myModal'> Edit </button>";
}
}
]
That shows the results of the query perfectly. As you can see, at the end oh the table appear a column with a edit button that must allow a user to modify note and status; this modified data must be send to a Spring controller with the id of the data to modify.
My problem is not how to send to controller; i solved this problem thanks to an user here on stack.
My problem is: if I want that { "data": "id" }
will be used, in modal, to set the data-id
on the button that trigger the modal, what syntax must I use? The actual syntax make me an error that tells "data is not defined" when I load the app. Seems that if I use the actual value, data-id=\""+data.id+"\"
, it don't recognize the data. notation to recall the data of data table columns.
EDIT: the markpsmith answer solve the problem of data not defined but I have still problems. His solution introduce another issue: now, when I submit form data, i got un "undefined" value on id. Analyzing the element i can note that it's undefined before I submit data form; immediately after the page is load, inspecting the button the value is undefined.
I've tried other solution found on web, but the problem is always the same: all the data and combination that I put on data-id are not recognized and this value is set to undefined.