I have problems giving rowspan to a table and grouped them based on parent row .I already tried to find some solution,but most of solution is to merge same values and not grouping them.
var data =
[
{
"LEVEL_1": "LEVEL 1",
"LEVEL_2": "LEVEL 1.1",
"LEVEL_3": "LEVEL 1.1.1",
},
{
"LEVEL_1": "LEVEL 1",
"LEVEL_2": "LEVEL 1.2",
"LEVEL_3": "LEVEL 1.2.1",
},
{
"LEVEL_1": "LEVEL 1",
"LEVEL_2": "LEVEL 1.2",
"LEVEL_3": "LEVEL 1.2.2",
},
{
"LEVEL_1": "LEVEL 2",
"LEVEL_2": "LEVEL 2.1",
"LEVEL_3": "LEVEL 2.1.1",
},
{
"LEVEL_1": "LEVEL 2",
"LEVEL_2": "LEVEL 2.1",
"LEVEL_3": "LEVEL 2.1.2",
},
{
"LEVEL_1": "LEVEL 2",
"LEVEL_2": "LEVEL 2.2",
"LEVEL_3": "LEVEL 2.2.1",
},
{
"LEVEL_1": "LEVEL 2",
"LEVEL_2": "LEVEL 2.2",
"LEVEL_3": "LEVEL 2.2.2",
}
];
var tableStr = '';
$.each(data, function(index, value) {
tableStr += '<tr>' +
'<td>'+value.LEVEL_1+'</td>'+
'<td>'+value.LEVEL_2+'</td>'+
'<td>'+value.LEVEL_3+'</td>'+
'</tr>';
});
$('#user tbody').html(tableStr);
table {
border-collapse: collapse;
}
td {
padding: 20px;
border: 1px solid black;
text-align: center;
}
th {
padding: 20px;
border: 1px solid black;
text-align: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="user">
<thead>
<tr>
<th>LEVEL 1</th>
<th>LEVEL 2</th>
<th>LEVEL 3</th>
</tr>
<tr>
</tr>
</thead>
<tbody>
</tbody>
</table>
I always found a result,it worked in the beginning. But when i added another level,but same data,it always looked like this
The JSON Data provided from Ajax request,was already given like that .Do i have to modify the JSON data and grouped them ? or it can be done using the given JSON Data ?How to do this using Jquery and JSON data ? Thanks in advance