I'm trying to put action buttons in my table through the datatTable plugin.
My Javascript code
$(document).ready(function(){
var table = $('#dataTable').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"contentType": "application/json",
"url": "http://localhost:8000/usuario/listar"
},
"columnDefs": [{
"targets": -1,
"data": null
}
}]
});
});
and my Controller in Codeigniter
<?php
class Usuario extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->model('UsuarioModel');
}
public function listar(){
$data = $this->UsuarioModel->all()->result();
$row = [];
foreach($data as $dados){
$row[] = array($dados->nome, $dados->endereco);
}
$d['data'] = $row;
echo json_encode($d);
}
}
The idea is that by DataTable it creates action buttons with "edit", "remove", "view" with the id on the button of my json answer.