[英]Datatable with nested table doesn't have functionality
The main function of this html file is to contain a main datatable that whenever I click on a row, It should show me a details table of data relating to that row but I've been having some isues. 该html文件的主要功能是包含一个主数据表,每当我单击一行时,它都应该向我显示与该行有关的数据的详细信息表,但是我遇到了一些问题。 First, the main table which I created as a datatable doesn't work with the functionality of a datatable, just with the functionality of a normal table. 首先,我创建为数据表的主表不适用于数据表的功能,而不能用于普通表的功能。 Second, whenever I click on the rows to display the details table, it only displays inside the first column of the main table. 其次,每当我单击行以显示详细信息表时,它仅显示在主表的第一列内。 Any help would be appreciated. 任何帮助,将不胜感激。
<html>
<head>
<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() {
var oTable = $('#maintable').dataTable( {
"aoColumnDefs": [
{ "bSortable": true, "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>Consulta de facturas atrasadas</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;
}
#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">
<h2>Consulta de facturas atrasadas</h2>
</div>
<div class="clr"></div>
</div>
</header>
<br>
<div id="container">
<table id="maintable" class="row-border hover order-column display table table-striped" 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 class="hiddenRow"><div class="accordian-body collapse" id="1">
<table id="a" class="table table-striped" style="width:100%; text-align: center">
<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 class="hiddenRow"><div class="accordian-body collapse" id="2">
<table id="b" class="table table-striped" style="width:100%; text-align: center">
<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>2012/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>
</table>
</div>
<script>
var table = document.getElementById("a");
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>
Your table doesn't have proper structure, there should be a match between number of th
elements in thead
and number of td
elements in tbody
. 您的表格结构不正确, thead
的th
元素数和tbody
的td
元素数应该匹配。 Here is corrected example https://jsfiddle.net/ocrhtupj/1/ , however row details are not shown correctly. 这是更正后的示例https://jsfiddle.net/ocrhtupj/1/ ,但是未正确显示行详细信息。
See Child rows for a proper implementation of a table with extra details with jQuery DataTables plugin. 有关使用jQuery DataTables插件的表格的正确详细信息,请参见子行 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.