How to make a datatable data be clickable by calling another view?

0

Good afternoon, guys. Here is the code for my view, which is working correctly. It happens that I would like to make the process number (2nd <td> ), be clickable by calling another view. Is it possible?

View Code:

<head>   
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.13/datatables.min.css"/>
    <script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.13/datatables.min.js"></script><scripttype="text/javascript" src="https://cdn.datatables.net/1.10.13/js/dataTables.bootstrap.min.js"></script></head><divclass="col-md-12">  
    <div class="row">
        <br>
        <div class="col-md-12">
            <p><font  size="3" face="helvetica"><strong>LISTA DE PROCESSOS</strong></font></p>                                                                           
        </div>
    </div>
    <div class="row">
        <div class="col-md-4 ">   
                <button type="button"  title="Imprimir" class="btn btn-primary  hidden-print" onclick="myFunction()">
                    <span class="glyphicon glyphicon-print" aria-hidden="true"></span></button>            
                <button  type="button" title="Cadastrar Processo" onclick="return window.location.href = '<?= base_url('processo/cadastro/') ?>'" class="btn btn-primary btn-sm hidden-print"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span>  PROCESSO</button>                                                                                                
        </div> 
    </div> 
    <br>
    <div class="row">        
        <div class="col-md-12">
            <table id="book-table" >
                <thead>
                    <tr>
                        <td><b>Cliente</b></td>
                        <td><b>Nº do Processo</b></td>                
                        <td><b>Parte</b></td>
                        <td><b>Pasta</b></td>
                        <td><b>Valor da causa</b></td>
                        <td><b>Situação</b></td>
                    </tr>
                </thead>
                <tbody>               
                </tbody>
            </table> 
        </div> 
    </div> 
</div>  
<script type="text/javascript">
    $(document).ready(function () {
        $('#book-table').DataTable({
            "autowidth": false,
            "ajax": {
                url: "<?php echo site_url("processo/processos_page") ?>",
                type: 'GET'
            }
        });
    });
</script>
<script>
    function myFunction() {
        window.print();
    }
</script>

Function Code in Controller:

public function processos_page() {

        // Datatables Variables
        $draw = intval($this->input->get("draw"));
        $start = intval($this->input->get("start"));
        $length = intval($this->input->get("length"));


        $processo = $this->Processo_model->getAll();

        $data = array();

        foreach ($processo->result() as $proc) {

            $data[] = array(
                $proc->nomecliente,
                $proc->nprocesso,
                $proc->nomeparte,                
                $proc->pastaescritorio,
                $proc->valorcausa,
                $proc->situacao
            );
        }

        $output = array(
            "draw" => $draw,
            "recordsTotal" => $processo->num_rows(),
            "recordsFiltered" => $processo->num_rows(),
            "data" => $data
        );
        echo json_encode($output);
        exit();
    }
    
asked by anonymous 23.05.2018 / 21:42

1 answer

1

Yes, does it this way

public function processos_page() {
$processo = $this->Processo_model->getAll();
$data = array();
$no = $_POST['start'];
foreach ($processo as $proc) {
    $no++;
    $row = array();

    $row[] =  $proc->nomecliente;
    $row[] =  " <div align='center'> <a  href='" . base_url() . "processor/ver/" . $ $proc->nprocesso . "'class='btn btn-success' ><i class='fa fa-search'></i></a> </div>";
    $row[] =   $proc->nomeparte;                
    $row[] =   $proc->pastaescritorio;
    $row[] =   $proc->valorcausa;
    $row[] =   $proc->situacao;


      $data[] = $row;
}

$output = array(
    "draw" => $_POST['draw'],
    "recordsTotal" => $this->processo->count_all(),
    "recordsFiltered" => $this->processo->count_filtered(),
    "data" => $data,
);

echo json_encode($output);

}

model, change your model if it is different for you to use Datatables the right way

// DataTables

var $table = "nome da sua tabela";
var $column = array('nome', 'cpf', 'data', 'rg', 'etc');
var $order = array('id' => 'asc', 'nome' => 'asc', 'cpf' => 'asc', 'data' => 'asc', 'rg' => 'asc');

private function _get_datatables_query() {
    $this->db->from($this->table);

    $i = 0;
    foreach ($this->column as $item) {
        if ($_POST['search']['value'])
            ($i === 0) ? $this->db->like($item, $_POST['search']['value']) : $this->db->or_like($item, $_POST['search']['value']);
        $column[$i] = $item;
        $i++;
    }

    if (isset($_POST['order'])) {
        $this->db->order_by($column[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
    } else if (isset($this->order)) {
        $order = $this->order;
        $this->db->order_by(key($order), $order[key($order)]);
    }
}

function get_datatables() {
    $this->_get_datatables_query();
    if ($_POST['length'] != -1)
        $this->db->limit($_POST['length'], $_POST['start']);
    $query = $this->db->get();
    return $query->result();
}

function count_filtered() {
    $this->_get_datatables_query();
    $query = $this->db->get();
    return $query->num_rows();
}

public function count_all() {
    $this->db->from($this->table);
    return $this->db->count_all_results();
}

Script to Call Datatables

<script type="text/javascript">

        var save_method; //for save method string
        var table;
        $(document).ready(function () {
            table = $('#book-table').DataTable({

                "processing": true, //Feature control the processing indicator.
                "serverSide": true, //Feature control DataTables' server-side processing mode.


                // Load data for the table's content from an Ajax source
                "ajax": {
                    "url": "<?php echo site_url('processo/processos_page') ?>",
                    "type": "POST"
                },
                "language": {
                    "sEmptyTable": "Nenhum registro encontrado",
                    "sInfo": "Mostrando de _START_ até _END_ de _TOTAL_ registros",
                    "sInfoEmpty": "Mostrando 0 até 0 de 0 registros",
                    "sInfoFiltered": "(Filtrados de _MAX_ registros)",
                    "sInfoPostFix": "",
                    "sInfoThousands": ".",
                    "sLengthMenu": "_MENU_ resultados por página",
                    "sLoadingRecords": "Carregando...",
                    "sProcessing": "Processando...",
                    "sZeroRecords": "Nenhum registro encontrado",
                    "sSearch": "Pesquisar",
                    "oPaginate": {
                        "sNext": "Próximo",
                        "sPrevious": "Anterior",
                        "sFirst": "Primeiro",
                        "sLast": "Último"
                    },
                    "oAria": {
                        "sSortAscending": ": Ordenar colunas de forma ascendente",
                        "sSortDescending": ": Ordenar colunas de forma descendente"
                    }
                },

                //Set column definition initialisation properties.
                "columnDefs": [
                    {
                        "targets": [-1], //last column
                        "orderable": false, //set not orderable
                    },
                ],

            });
        });


        function reload_table()
        {
            table.ajax.reload(null, false); //reload datatable ajax
        }

    </script>
    
24.05.2018 / 21:26