Hi to everyone.
I´m passing some data to a view using this code:
public function indexAction()
{
$userId = $this->auth->getId();
$data = [];
$contas = Users::findFirst($userId)->accountuser;
foreach ($contas as $conta) {
$data[] = [$conta->id, $conta->account->tradename, $conta->profile->name];
}
$this->view->data = json_encode($data);
}
In the view I´m using datables to show the data:
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
<script>
$(document).ready(function() {
var tableadmin = $('#contas').DataTable( {
"dom": '<"top"f>tp',
"data": {{ data }},
"language": {
"search": "Buscar:",
"paginate": {
"first": "Início",
"last": "Final",
"next": "Próximo",
"previous": "Anterior"
},
},
"columnDefs": [
{
"targets": [ 0 ],
"visible": false,
"searchable": false
}
]
} );
$('#contas tbody').on('click', 'tr', function () {
var data = tableadmin.row( this ).data()[0];
window.location.href = '/accounts/select/' + data;
} );
});
</script>
Everything is workling fine, but when I put the js script to an external js file using this:
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
{{ javascriptInclude('js/accountindex.js') }}
The data doesn´t appear. Is there anything wrong?