how can i get the form(input) data in datatable?
how can i get the form(input) data in datatable?
noodle_lin
Posts: 6Questions: 2Answers: 0
in DataTables
Link to test case:
** code**:
<script>
$(document).ready(function () {
var table = $('#example').DataTable({
"ajax": {
url: "/admin/data/base.json",
dataSrc: ""
},
"columns": [
{title:'first', data: 'first'},
{title:'second', data: 'second'},
{title:'third', data: 'third'},
{title:'fourth', data: 'fourth'}],
"columnDefs": [
{
targets: [0, 2],
render: function (data, type, row, meta) {
if (type === 'display') {
return '<input type="text" value="' + data + '">';
}
return data;
},
}
],
destroy: true
})
;
$('button').click(function () {
var data = table.$('input, select').serialize();
alert("The following data would have been submitted to the server: \n\n"+
data +'...'
);
});
});
</script>
<button type="submit">Submit form</button>
<table id="example" class="display" style="width:100%">
</table>
Description of problem:
when i submit, it returns
seems that the data is empty...
how can i fix it?
Answers
You are creating a text input with this:
But you are trying to retrieve select inputs with this:
Try changing to this:
Kevin
@kthorngren remain the same. data is empty.
is there something to do with how i create the text input or how i post data into datatable?
because when i change
var data = table.$('input, text').serialize();
into
var data = table.data()
it returns sth below after submit
this is the DT
It might be worth looking at Editor - as that's designed to easily submit the data to the server.
Colin