У меня есть таблица вроде этого
=============== | 1 | 1 | 1 | | | === | | | 2 | | | === | | | 3 | ========= | 2 | 1 | | | === | | | 2 | | | === | | | 3 | =============== | 2 | 1 | 1 | | | === | | | 2 | | | === | | | 3 | ========= | 2 | 1 | | | === | | | 2 | | | === | | | 3 | ==============
как я могу сделать таблицу, подобную этой, на основе данных базы данных, которые будут занимать строки, если данные имеют одинаковый идентификатор, используя данные jquery json?
РЕДАКТИРОВАТЬ!
это моя функция ajax
$.ajax({ method:'POST', async:true, url:"<?php echo base_url()?>dashboard/showTableKondisi", datatype:'json', success:function(data){ var json = $.parseJSON(data); var html = ''; var i; if(Object.keys(json.data).length > 0){ for(i=0,no=1,no2=1;i<Object.keys(json.data).length;i++){ var length_data_sebab_new = 0 for(var x=0; x<Object.keys(json.data[i].data_sebab).length; x++){ for(var y=0; y<Object.keys(json.data[i].data_sebab[x].data_rekomendasi).length; y++){ length_data_sebab_new = Object.keys(json.data[i].data_sebab[x].data_rekomendasi).length; } } var length_data_sebab_new_new = length_data_sebab_new; var length_data_sebab = (Object.keys(json.data[i].data_sebab).length)-(-1)-(-length_data_sebab_new_new) ; html+='<tr><td rowspan="'+length_data_sebab+'">'+no+'</td><td rowspan="'+length_data_sebab+'"><button class="btn btn-default" type="button" onClick="javascript:tambahsebab(this.id)" id="'+json.data[i].id+'"><i class="fa fa-plus"></i> Penyebab</button><button class="btn btn-default pull-left" type="button" id="edit_kondisi"><i class="fa fa-pencil"></i> Edit</button><br><br>'+json.data[i].memo_kondisi+'<br>Rp '+json.data[i].nilai_temuan+'</td>'; for(var x=0; x<Object.keys(json.data[i].data_sebab).length; x++){ var length_data_rekomendasi = (Object.keys(json.data[i].data_sebab[x].data_rekomendasi).length)-(-1); // console.log(Object.keys(json.data[i].data_sebab[x].data_rekomendasi).length); no2 = x-(-1); html+='<tr><td rowspan="'+length_data_rekomendasi+'" >'+no2+'</td><td rowspan="'+length_data_rekomendasi+'"><button class="btn btn-default" type="button" onClick="javascript:tambahrekomendasi(this.id)" id="'+json.data[i].data_sebab[x].id+'"><i class="fa fa-plus"></i> Rekomendasi</button><button class="btn btn-default pull-left" type="button" id="edit_sebab"><i class="fa fa-pencil"></i> Edit</button><br><br>'+json.data[i].data_sebab[x].id+'<br>Rp '+json.data[i].data_sebab[x].nilai_temuan+'</td>'; for(var y=0; y<Object.keys(json.data[i].data_sebab[x].data_rekomendasi).length; y++){ no3 = y-(-1); html+='<tr><td>'+no3+'</td><td><button class="btn btn-default" type="button" onClick="javascript:tambahrekomendasi(this.id)" id="'+json.data[i].data_sebab[x].data_rekomendasi[y].id+'"><i class="fa fa-plus"></i> Tindak Lanjut</button><button class="btn btn-default pull-left" type="button" id="edit_sebab"><i class="fa fa-pencil"></i> Edit</button><br><br>'+json.data[i].data_sebab[x].data_rekomendasi[y].id+'<br>Rp aaa'+json.data[i].data_sebab[x].data_rekomendasi[y].nilai_temuan+'</td></tr>'; // } html+='</tr>'; } html+='</tr>'; no+=1; no2+=1; no } }else{ html+=''; } $('#kondisi_tabel').html(html); // $('#s_sub_kondisi').html(html2); }, error:function(){ alert('tidak dapat membaca database') } })
ИЗМЕНИТЬ 3
мой прогресс до сих пор такой. я сделал таблицу отлично, но когда второй td одной и той же строки tr, td имеет другой td справа, он разбился
Мои новые данные JSON
Обновление 24 июля 2017 года
{ "data": [ { "id": "14", "memo_kondisi": "Kekurangan pekerjaan", "total_row": "5", "nilai_temuan": "1.000.000", "data_sebab": [ { "id": "15", "id_sebab": "", "id_sub_sebab": "", "memo_sebab": "coba", "data_rekomendasi": [ { "id": "25", "id_rekomendasi": "10", "id_sub_rekomendasi": "", "id_s_sub_rekomendasi": "", "nilai_rekomendasi": "0" }, { "id": "26", "id_rekomendasi": "10", "id_sub_rekomendasi": "", "id_s_sub_rekomendasi": "", "nilai_rekomendasi": "0" }, { "id": "31", "id_rekomendasi": "10", "id_sub_rekomendasi": "", "id_s_sub_rekomendasi": "", "nilai_rekomendasi": "0" } ] }, { "id": "16", "id_sebab": "", "id_sub_sebab": "", "memo_sebab": "coba", "data_rekomendasi": [ { "id": "34", "id_rekomendasi": "10", "id_sub_rekomendasi": "", "id_s_sub_rekomendasi": "", "nilai_rekomendasi": "0" }, { "id": "35", "id_rekomendasi": "10", "id_sub_rekomendasi": "", "id_s_sub_rekomendasi": "", "nilai_rekomendasi": "0" } ] } ] }, { "id": "15", "memo_kondisi": "Kekurangan pekerjaan", "total_row": "2", "nilai_temuan": "1.000.000", "data_sebab": [ { "id": "5", "id_sebab": "", "id_sub_sebab": "", "memo_sebab": "coba", "data_rekomendasi": [] }, { "id": "10", "id_sebab": "", "id_sub_sebab": "", "memo_sebab": "coba", "data_rekomendasi": [] } ] }, { "id": "16", "memo_kondisi": "", "total_row": "2", "nilai_temuan": "0", "data_sebab": [ { "id": "9", "id_sebab": "", "id_sub_sebab": "", "memo_sebab": "coba", "data_rekomendasi": [] }, { "id": "12", "id_sebab": "", "id_sub_sebab": "", "memo_sebab": "coba", "data_rekomendasi": [] } ] } ] }