Я пытаюсь реализовать Jatery Datatable с несколькими флажками.Я следовал приведенному ниже примеру -
<code>$(document).ready(function (){
var table = $('#example').DataTable({
'ajax': 'logapi3.php?query=query_01',
'columnDefs': [{
'targets': 0,
'searchable':false,
'orderable':false,
'className': 'dt-body-center',
'render': function (data, type, full, meta){
return '<input type="checkbox" name="id[]" value="'
+ $('<div/>').text(data).html() + '">';
}
}],
'order': [1, 'asc']
});
// Handle click on "Select all" control
$('#example-select-all').on('click', function(){
// Check/uncheck all checkboxes in the table
var rows = table.rows({ 'search': 'applied' }).nodes();
$('input[type="checkbox"]', rows).prop('checked', this.checked);
});
// Handle click on checkbox to set state of "Select all" control
$('#example tbody').on('change', 'input[type="checkbox"]', function(){
// If checkbox is not checked
if(!this.checked){
var el = $('#example-select-all').get(0);
// If "Select all" control is checked and has 'indeterminate' property
if(el && el.checked && ('indeterminate' in el)){
// Set visual state of "Select all" control
// as 'indeterminate'
el.indeterminate = true;
}
}
});
$('#frm-example').on('submit', function(e){
var form = this;
// Iterate over all checkboxes in the table
table.$('input[type="checkbox"]').each(function(){
// If checkbox doesn't exist in DOM
if(!$.contains(document, this)){
// If checkbox is checked
if(this.checked){
// Create a hidden element
$(form).append(
$('<input>')
.attr('type', 'hidden')
.attr('name', this.name)
.val(this.value)
);
}
}
});
// FOR TESTING ONLY
// Output form data to a console
$('#example-console').text($(form).serialize());
console.log("Form submission", $(form).serialize());
// Prevent actual form submission
e.preventDefault();
});
});
<form id="frm-example" action="/path/to/your/script" method="POST">
<table id="example" class="table table-bordered table-hover table-striped" style="width:100%">
<thead>
<tr>
<th><input name="select_all" value="1" id="example-select-all" type="checkbox" /></th>
<th>Schema</th>
<th>Table Name</th>
<th>BI Service</th>
<th>Business Owner</th>
<th>Solution Owner</th>
<th>Last Update Time</th>
</tr>
</thead>
</table>
<p><button>Submit</button></p>
</div>
<b>Data submitted to the server:</b><br>
<pre id="example-console">
JSFIDDLE
Это работает довольно хорошо, но я только получаю значениеID.Мне нужно получить значения следующих 2 столбцов.Возможно, ".closest ('tr'). Find ('td: eq (1)')" должен работать.Но так как я не являюсь разработчиком Javascript / Jquery, не могу исправить эту часть.Также хотел бы знать, что должно быть "action =" / path / to / your / script "" для моего случая.