I am using the jQuery DataTables and I am encountering the following problem: when I click on a button I need to pass a value with jQuery to the input that has the id "tipo_venta2" of the datatable's footer, but it does not work for me, I would like know how I should do it. What would be the right way to do it?
Here I show the minimum, complete and executable example:
$(document).ready(function () {
var table_ = $('#table_').DataTable({
"scrollY": "300px",
"searching": false,
"paging": false,
"ordering": false,
"info": false,
"columns": [
{ "width": "5%" },
{ "width": "5%" },
{ "width": "8%" },
{ "width": "6%" },
{ "width": "8%" },
{ "width": "39%" },
{ "width": "8%" },
{ "width": "8%" },
{ "width": "5%" },
{ "width": "8%" }
],
fixedHeader: {
header: true,
footer: true
}
});
$("#test").click(function (e) {
e.preventDefault();
$('#table_ tfoot th input[id=tipo_venta2]').val("valor a copiar de prueba");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" />
<input id="test" type="submit" value="test" />
<table id="table_" class="table table-striped table-bordered" style="margin-bottom: 0 !important;">
<thead>
<tr style="background-color: #ff6a00; color: #fff">
<th>dat</th>
<th>dat</th>
<th>dat</th>
<th>dat</th>
<th>dat</th>
<th>dat</th>
<th>dat</th>
<th>dat</th>
<th>dat</th>
<th>dat</th>
</tr>
</thead>
<tfoot>
<tr>
<th style="border:0 !important;border-collapse:separate !important;" colspan="6">
<input type="text" class="form-control_tablegrande" id="tipo_venta2" placeholder="VENTAS">
</th>
<th style="border:0 !important;border-collapse:separate !important; text-align:right"><span style="font-weight:normal !important;vertical-align:middle">Totales Iguales</span></th>
<th style="border:0 !important;border-collapse:separate !important;"></th>
<th style="border:0 !important;border-collapse:separate !important;"> </th>
<th style="border:0 !important;border-collapse:separate !important;"></th>
</tr>
</tfoot>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
I've noticed that the problem occurs when I define "scrollY": "300px"
, which prevents me from copying data to the footer input. As you can see in the following code that works without problems when commenting that line:
$(document).ready(function () {
var table_ = $('#table_').DataTable({
//"scrollY": "300px",
"searching": false,
"paging": false,
"ordering": false,
"info": false,
"columns": [
{ "width": "5%" },
{ "width": "5%" },
{ "width": "8%" },
{ "width": "6%" },
{ "width": "8%" },
{ "width": "39%" },
{ "width": "8%" },
{ "width": "8%" },
{ "width": "5%" },
{ "width": "8%" }
],
fixedHeader: {
header: true,
footer: true
}
});
$("#test").click(function (e) {
e.preventDefault();
$('#table_ tfoot th input[id=tipo_venta2]').val("valor a copiar de prueba");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" />
<input id="test" type="submit" value="test" />
<table id="table_" class="table table-striped table-bordered" style="margin-bottom: 0 !important;">
<thead>
<tr style="background-color: #ff6a00; color: #fff">
<th>dat</th>
<th>dat</th>
<th>dat</th>
<th>dat</th>
<th>dat</th>
<th>dat</th>
<th>dat</th>
<th>dat</th>
<th>dat</th>
<th>dat</th>
</tr>
</thead>
<tfoot>
<tr>
<th style="border:0 !important;border-collapse:separate !important;" colspan="6">
<input type="text" class="form-control_tablegrande" id="tipo_venta2" placeholder="VENTAS">
</th>
<th style="border:0 !important;border-collapse:separate !important; text-align:right"><span style="font-weight:normal !important;vertical-align:middle">Totales Iguales</span></th>
<th style="border:0 !important;border-collapse:separate !important;"></th>
<th style="border:0 !important;border-collapse:separate !important;"> </th>
<th style="border:0 !important;border-collapse:separate !important;"></th>
</tr>
</tfoot>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
Why does the error occur when I put that attribute in the configuration? How can I make it work in both cases without problems?