DataTables JQuery does not render column button in Codeigniter

0

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.     

asked by anonymous 07.02.2018 / 15:20

1 answer

1

Replace this part of your code:

            $row[] = array($dados->nome, $dados->endereco);

by this:

           $row[] = $dados->nome;
           $row[] =  $dados->endereco;
           $row[] = "<a href='" . base_url() . "controle/editar/" . $dados->id . "'class='btn btn-primary' >Editar</a>";
    
21.05.2018 / 19:03