I have a problem loading datatables object. When I initialize and populate table on page load it works properly.
THIS CODE BELOW WORKS PERFECT AT PAGE RELOAD.
<script src="https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
var table = $('#dt_110x_complex').DataTable({
paging : true,
scrollY: 300,
ajax: "{{ url_for('complex_data') }}"
});
});
</script>
But this code below DOES NOT WORK on button click. What am I doing wrong?
$(function() {
$('#proces_input').on('click', function() {
alert('Im in')
var table = $('#dt_110x_complex').DataTable({
paging : true,
scrollY: 300,
ajax: "{{ url_for('complex_data') }}"
});
});
});
The button id = "proces_input". Message alert('Im in') shows after button click.
Below is my html table code (for both samples the same) for datatables.:
<div class="row">
<div class="col-lg-12">
<table id="dt_110x_complex" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>id</th>
<th>code</th>
<th>date</th>
<th>blocade</th>
<th>konti</th>
<th>free</th>
<th>occ</th>
<th>origin</th>
<th>type</th>
<th>created</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>