Data-Table does not work with Codeigniter

Asked

Viewed 105 times

0

The page does not show the data-table, only the table created in codeigniter. It follows codes CONTROLLER

public function gerenciar(){
    esta_logado();
    set_tema('footerinc', load_js(array('data-table','table')), FALSE); //carrega arquivos js
    set_tema('titulo','Gerenciamento de usuários');
    set_tema('conteudo',load_modulo('usuarios','gerenciar'));
    load_template();
}

VIEW

case 'gerenciar':
    ?>
    <div class="large-12 columns">
        <table id="table" class="large-12 data-table">
            <thead>
                <tr>
                    <th>Nome</th>
                    <th>login</th>
                    <th>Email</th>
                    <th>Ativo / Adm</th>
                    <th>Ações</th>
                </tr>
            </thead>
            <tbody>
                <?php 
                $query = $this->usuarios->get_all()->result();
                foreach ($query as $linha) :
                    echo '<tr>';
                    printf('<td>%s</td>', $linha->nome);
                    printf('<td>%s</td>', $linha->login);
                    printf('<td>%s</td>', $linha->email);
                    printf('<td>%s / %s</td>', ($linha->ativo==0) ? 'Não' : 'Sim', ($linha->adm==0) ?   'Não' : 'Sim');
                    printf('<td>%s</td>', 'Ações');
                    echo '</tr>';
                endforeach;
                ?>
            </tbody>
        </table>
    </div>

MODEL

public function get_all(){
        return $this->db->get('usuarios');
    }

Follow JS file

$(document).ready(function(){
    $(".table").DataTable({
        "sScrollY": "400px",
        "sScrollX": "100%",
        "sScrollXInner": "100%",
        "bPaginate": false,
        "aaSorting": [[0, "asc"]]
    });
});

1 answer

1

Selector is wrong, exchange ". table" for "#table"

$(document).ready(function(){
    $("#table").DataTable({
        "sScrollY": "400px",
        "sScrollX": "100%",
        "sScrollXInner": "100%",
        "bPaginate": false,
        "aaSorting": [[0, "asc"]]
    });
});
  • Thanks for the reply Hendrik, but unfortunately the table remains the same, none of the aspects of datatable is working!

  • Checked if there is a javascript error in the browser console?

  • The site menu is in javascript and is working correctly.... and by the final source code, I saw that it is still able to search normally the JS file

Browser other questions tagged

You are not signed in. Login or sign up in order to post.