How do I put two Datatables on the same page?

Asked

Viewed 800 times

0

The first table picks right but the second load is not the table without the Datatable attributes. How do I use both on the same page?

2 answers

2

already try div with id ?

<div class="" id="datatables1">
 conteudo 1
</div>
<div class="" id="datatables2">
 conteudo 2
</div> 

got it ?

  • I tried now it wasn’t.

  • use the example above, it’s almost the same as my http://prntscr.com/i29dtu

  • Now that I understand you have to activate the script so I wasn’t getting it, I just marked the other friend’s answer because it was more complete,.

  • Normal :v I appreciate you trying to help me, or meeting someone great in php to help me in my poster :P https://answall.com/questions/269993/fun%C3%A7%C3%A3o-exec-chama-programa-em-segundo-plano? noredirect=1#comment552952_269993

2


Here’s a basic example of how to do for a better use of all functions of the datatable look Aki: https://datatables.net/examples/index and for other examples

$(document).ready(function() {
    $('#example').DataTable( {
        data: [
          [ "Garrett Winters", "Accountant", "Tokyo", "8422", "2011/07/25", "$170,750" ],
          [ "Ashton Cox", "Junior Technical Author", "San Francisco", "1562", "2009/01/12", "$86,000" ]
        ],
        columns: [
            { title: "Name" },
            { title: "Position" },
            { title: "Office" },
            { title: "Extn." },
            { title: "Start date" },
            { title: "Salary" }
        ]
    } );
    $('#example2').DataTable({
        data: [
          [ "Tiger Nixon", "System Architect", "Edinburgh", "5421", "2011/04/25", "$320,800" ]],
    });
} );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<link href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet"/>
<table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Extn.</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Extn.</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </tfoot>
    </table>
    <br>
    <br>
    <table id="example2" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Extn.</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Extn.</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </tfoot>
    </table>

  • I’m picking up the data with a php foreach, have as I do with it?

  • @Evertonfigueiredo There are several ways to implement this , the best would be to see the various ways to fill the table in the indicated link and choose the best way for your system.

Browser other questions tagged

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