Add datable functionality to bootstrap accordion table

时间:2016-04-15 15:04:16

标签: html css twitter-bootstrap twitter-bootstrap-3 datatables

I'm trying to do an accordion type table with another table inside every row and want the main table to have datatable functionality but whenever I try to use the datatable with bootstrap functionality at the same time, the datatable doesn't works. It only works when I'm not using the bootstrap accordion feature. Here's the code:

<html>

<head>

    <!DOCTYPE html>

    <script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
    <script src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/responsive/2.0.2/js/dataTables.responsive.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css">
    <link rel="stylesheet" href="https://cdn.datatables.net/responsive/2.0.2/css/responsive.dataTables.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <link rel="icon" href="./resources/logo.jpg">



<script>     

    $(document).ready(function() {

        $('#maintable').dataTable( {

            "aoColumnDefs": [
                { "bSortable": false, "aTargets": [ 0 ] }
            ],
            "aaSorting": [[1, 'asc']],

            "language": {
                "lengthMenu": "Mostrar _MENU_ datos por pagina.",
                "zeroRecords": "Nada fue encontrado.",
                "info": "Mostrando _PAGE_ de _PAGES_",
                "infoEmpty": "No hay datos disponibles",
                "infoFiltered": "(filtrado de _MAX_ datos totales)",
                "search": "Buscar:",
                "paginate": {
                    "first":      "Primero",
                    "last":       "Ultimo",
                    "next":       "Proximo",
                    "previous":   "Previo"
                }
            }

        }); 
     });

</script>   




    <title></title>

    <style type="text/css">
        html, #page { padding:0; margin:0;}
        body { margin:0; padding:0; width:100%; color:#959595; font:normal 12px/2.0em Sans-Serif;} 
        h1, h2, h3, h4, h5, h6 {color:darkblue; text-align: center;}

        #page { background:#fff;}
        #header, #footer{ margin:0; padding:0;}


        #logo { padding:0; width:auto; text-align: center; margin: auto;}

        #header { background:#fff; }
        #header-inner { margin:0 auto; padding:0;}


        #footerblurb { background:#d3d3f9;color:blue; width: 100%;}     

        #footer { background:#fff; width: 100%;}
        #footer-inner { margin:auto; text-align:center; padding:12px;}
        #footer a {color:blue;text-decoration:none;}

        #maintable {

            text-align: center;             

        }

        .hiddenRow {
            padding: 0 !important;
        }   

        #insideTable {
            width:100%;
            text-align: center;
        }

        #events {
            margin-bottom: 1em;
            padding: 1em;
            background-color: #f6f6f6;
            border: 1px solid #999;
            border-radius: 3px;
            height: 100px;
            overflow: auto;
        }

        td.highlight {
            background-color: whitesmoke !important;
        }

        .details-control {


        }

        #container {

            width:90%;
            margin: 0 auto;

        }

        #titulo {

            margin: 0 auto;

        }


        div.slider {
            display: none;
        }

        table.dataTable tbody td.no-padding {
            padding: 0;
        }

        th {

            text-align: center;

        }

        .bodycontainer { max-height: 450px; width: 100%; margin: 0; overflow-y: auto; }


        #col-lg-6 {
            margin: auto;
        }

        #formulario{
            margin: auto;
            column-width: 80%;
        }
        .clr { clear:both; padding:0; margin:0; width:100%; font-size:0px; line-height:0px;}

    </style>

</head>

<body>

        <br>
    <div id="page">
        <header id="header">
            <div id="header-inner"> 
                <div id="logo">

                </div>

                <div id="titulo">

                </div>

                <div class="clr"></div>
            </div>
        </header>
        <br>    

        <div id="container">

        <table id="maintable"  cellspacing="0" width="100%" style="border-collapse:collapse;">
            <thead>
                <tr>

                    <th>Codigo</th>
                    <th>Nombre</th>
                    <th>Propietario</th>
                    <th>Direccion</th>
                    <th>Ciudad</th>
                    <th>Sector</th>
                    <th>Cedula</th>
                    <th>Tel. 1</th>
                    <th>Tel. 2</th>
                    <th>Celular</th>

                </tr>
            </thead>


            <tbody>

                <tr data-toggle="collapse" data-target="#1" class="accordion-toggle">

                    <td>Codigo</td>
                    <td>2011/02/02</td>
                    <td>Propietario</td>
                    <td>Direccion</td>
                    <td>Ciudad</td>
                    <td>Sector</td>
                    <td>Cedula</td>
                    <td>Tel. 1</td>
                    <td>Tel. 2</td>
                    <td>Celular</td>

                </tr>

                    <tr>

                        <td colspan="10" class="hiddenRow"><div class="accordian-body collapse" id="1"> 
                          <table id="insidetable" class="table table-striped">
                                  <thead>

                                    <tr> 
                                        <th>Factura</th> 
                                        <th>Fecha</th> 
                                        <th>Dias</th> 
                                        <th>Monto</th> 
                                        <th>Pendiente</th> 
                                        <th>Vendedor</th> 
                                    </tr>


                                  </thead>

                                  <tbody>

                                    <tr> 
                                        <td>Factura</td> 
                                        <td>2015/04/15</td> 
                                        <td>Factura</td> 
                                        <td>Factura</td> 
                                        <td>Factura</td> 
                                        <td>Factura</td> 
                                    </tr>

                                    <tr> 
                                        <td>Factura</td> 
                                        <td>2011/04/15</td> 
                                        <td>Factura</td> 
                                        <td>Factura</td> 
                                        <td>Factura</td> 
                                        <td>Factura</td> 
                                    </tr>

                                  </tbody>

                          </table>
                        </div>
                        </td>

                    </tr>




                <tr data-toggle="collapse" data-target="#2" class="accordion-toggle">

                    <td>Codigo</td>
                    <td>Nombre</td>
                    <td>Propietario</td>
                    <td>Direccion</td>
                    <td>Ciudad</td>
                    <td>Sector</td>
                    <td>Cedula</td>
                    <td>Tel. 1</td>
                    <td>Tel. 2</td>
                    <td>Celular</td>

                </tr>

                    <tr>

                        <td colspan="10" class="hiddenRow"><div class="accordian-body collapse" id="2"> 
                          <table id="insidetable" class="table table-striped">
                                  <thead>

                                    <tr> 
                                        <th>Factura</th> 
                                        <th>Fecha</th> 
                                        <th>Dias</th> 
                                        <th>Monto</th> 
                                        <th>Pendiente</th> 
                                        <th>Vendedor</th> 
                                    </tr>


                                  </thead>

                                  <tbody>

                                    <tr> 
                                        <td>Factura</td> 
                                        <td>2015/04/15</td> 
                                        <td>Factura</td> 
                                        <td>Factura</td> 
                                        <td>Factura</td> 
                                        <td>Factura</td> 
                                    </tr>

                                    <tr> 
                                        <td>Factura</td> 
                                        <td>2011/04/15</td> 
                                        <td>Factura</td> 
                                        <td>Factura</td> 
                                        <td>Factura</td> 
                                        <td>Factura</td> 
                                    </tr>

                                  </tbody>

                          </table>
                        </div>
                        </td>

                    </tr>                       

                <tr>

                    <td>Codigo</td>
                    <td>Nombre</td>
                    <td>Propietario</td>
                    <td>Direccion</td>
                    <td>Ciudad</td>
                    <td>Sector</td>
                    <td>Cedula</td>
                    <td>Tel. 1</td>
                    <td>Tel. 2</td>
                    <td>Celular</td>

                </tr>
                <tr>

                    <td>Codigo</td>
                    <td>2011/02/02</td>
                    <td>Propietario</td>
                    <td>Direccion</td>
                    <td>Ciudad</td>
                    <td>Sector</td>
                    <td>Cedula</td>
                    <td>Tel. 1</td>
                    <td>Tel. 2</td>
                    <td>Celular</td>

                </tr>
                <tr>

                    <td>Codigo</td>
                    <td>Nombre</td>
                    <td>Propietario</td>
                    <td>Direccion</td>
                    <td>Ciudad</td>
                    <td>Sector</td>
                    <td>Cedula</td>
                    <td>Tel. 1</td>
                    <td>Tel. 2</td>
                    <td>Celular</td>

                </tr>
            </tbody>

        </div>    


        </table>    


        <script>
          var table = document.getElementById("insidetable");
          for(var i = 0; i < table.rows.length; i ++) {
            var d = new Date(table.rows[i].cells[1].innerHTML).getTime();
            var difference = new Date().getTime();
            console.log(((difference - d)/86400000) > 100);
            if(((difference - d)/86400000) > 1000)
              table.rows[i].style.background = "red";
          }
        </script>   




                <div class="clr"></div>



        <footer id="footer">

            <div id="footerblurb">
                <br>
            </div>

            <div id="footer-inner">

                <div class="clr"></div>
            </div>

        </footer>

    </div>

</body>

</html>

0 个答案:

没有答案
相关问题