Reputation: 75
Hello my office the next, I happen to have a table generated in html, but I want to capture all the structure of the table without considering the entire first column, until now could only manage to capture all components in a variable, but I need to improve it to capture all but the first column of the table.
.html
<table border="1" id="tblConsulta">
<thead>
<tr>
<th>Eliminar</th>
<th>Dependencia</th>
<th>UU.OO</th>
<th>Documento</th>
<th>Reg</th>
<th>Responsable</th>
<th>Fecha Inicio</th>
<th>Fecha Fin</th>
<th>Fecha Autoriz</th>
<th>Estado</th>
<th>Motivo</th>
</tr>
</thead>
<tr>
<td><input class="editor-active" value="74" disabled="" type="checkbox" /></td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
</tr>
</table>
javascript
var output = '';
$("[id=tblConsulta]").each(function() {
output += $(this).find("thead").html();
$('#tblConsulta tbody tr').each(function() {
var j = 0;
output += '<tr class="">';
$.each(this.cells, function() {
j++;
if (j < 12) {
if (j == 5) {
output += '<td class="date">';
} else if (j == 3) {
output += '<td class="number">';
} else {
output += '<td class="text">';
output += $(this).html();
output += '</td>';
}
}
});
output += '</tr>';
});
});
console.log(output);
I hope you can help me, the idea is to capture the chexbox not want to label in the chain, because then I want to print it in a report.
I have also published jsFiddle: https://jsfiddle.net/movboj2m/
Upvotes: 1
Views: 71
Reputation: 8513
Try straight up removing the first column from the table, after having saved it first. Then after your log is printed, put the table back in its original condition, aka:
var output = '';
var saveTable = $("table").html();
$("table").find("th:first").remove();
$("table").find("tr").each(function() {
$(this).find("td:first").remove();
});
$("[id=tblConsulta]").each(function() {
output += $(this).find("thead").html();
$('#tblConsulta tbody tr').each(function() {
var j = 0;
output += '<tr class="">';
$.each(this.cells, function() {
j++;
if (j < 12) {
if (j == 5) {
output += '<td class="date">';
} else if (j == 3) {
output += '<td class="number">';
} else {
output += '<td class="text">';
output += $(this).html();
output += '</td>';
}
}
});
output += '</tr>';
});
});
console.log(output);
$("table").html(saveTable);
.title{
font-weight:bold;
}
.index {
height: 30px;
width: 40px;
display: inline-block;
border: 1px solid white;
background-color: cadetblue;
color: black;
text-align: center;
line-height: 30px;
}
.prev {
height: 30px;
width: 40px;
display: inline-block;
border: 1px solid white;
background-color: cadetblue;
color: black;
text-align: center;
line-height: 30px;
}
.next {
height: 30px;
width: 40px;
display: inline-block;
border: 1px solid white;
background-color: cadetblue;
color: black;
text-align: center;
line-height: 30px;
}
.clicked{
height: 30px;
width: 40px;
display: inline-block;
border: 1px solid black;
background-color: #993333;
color: white;
text-align: center;
line-height: 30px;
}
.enter{
color: white;
border: 1px solid black;
}
#result1{
margin-top: 10px;
margin-left: 300px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table border="1" id="tblConsulta">
<thead>
<tr>
<th>Eliminar</th>
<th>Dependencia</th>
<th>UU.OO</th>
<th>Documento</th>
<th>Reg</th>
<th>Responsable</th>
<th>Fecha Inicio</th>
<th>Fecha Fin</th>
<th>Fecha Autoriz</th>
<th>Estado</th>
<th>Motivo</th>
</tr>
</thead>
<tr>
<td><input class="editor-active" value="74" disabled="" type="checkbox" /></td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
</tr>
</table>
Upvotes: 1
Reputation: 12004
Use tblConsulta tr:gt(1)
. gt selector: https://api.jquery.com/gt-selector/
Upvotes: 2