I have an ordinary table generated with Ajax sourced data, it looks like this:
Ajax
<script>
$(document).ready(function() {
$('#mytable').DataTable( {
"ajax": "myurl",
"dataType": 'json',
"dataSrc": '',
"columns": [
{"data": "item"},
{"data": "status"},
{"data": "price"},
]
} );
} );
</script>
Html
<table id="mytable" class="display" style="width:100%">
<thead>
<tr>
<th>ITEM</th>
<th>STATUS</th>
<th>PRICE</th>
</tr>
</thead>
</table>
I would like to add a new column to this table, basically each row should have a form that, when hit, will fire an Ajax request containing the value of the field Status, so i should have:
<th>ITEM</th>
<th>STATUS</th>
<th>PRICE</th>
<th>BUTTON</th>
Here is my form:
<script>
$(document).ready(function () {
$("#myform").submit(function (event) {
callAJAX( "myurl/",
{"X-CSRFToken": getCookie("csrftoken") },
parameters={'status': $('status').val()},
'post',
function(data){
console.log('submitted')
}, null, null );
return false;
});
});
</script>
<form method='post' id='myform'>
{% csrf_token %}
<input type="hidden" id="status"/>
<button name="button1" type="submit" class="btn btn-primary">SEND</button>
</form>
So, each row has four fields: item, status, price, button. On every row there is a button below the column button. When the button on a row is hit, ajax should send a post request with the value of status for that particular row. Is there any way to do it? The biggest problem here is adding the form to Datatable, i did not find much about how to do it. Any advice is appreciated