2017-04-11 80 views
0

我想在使用循環的數據表中的同一行中創建動態表列。但我不能這樣做。使用循環我想和值在不同的列,但在同一行不同的ID添加不同的選擇框,請幫助.. 這是我的代碼..在數據表中添加同一行中的動態列

for (var count=1;count<=sessionStorage.getItem('differ');count++) 
{ 
    var j=count; 


$.ajax({ 
     url:serverURL2+'get_list_of_cme_application_by_cme_id/'+ac_id, 
     dataType: 'json', 
     type: 'get', 
     success: function(data){ 
      if(data.error){ 
       alert("Record not found!"); 
      }else{ 


       table=$("#example4").DataTable(); 
       table.rows().remove().draw(); 
       $.map(data.application_list,function(item){ 




       var d = item.created_by_date_time; 
       d = d.split(' ')[0]; 

       var date = new Date(d), 
       yr  = date.getFullYear(), 
       month = date.getMonth() < 10 ? '0' + date.getMonth() : date.getMonth(), 
       day  = date.getDate() < 10 ? '0' + date.getDate() : date.getDate(), 
       newDate = day + '-' + month + '-' + yr; 

       var sdd=new Date(item.start_date); 
       yr1  = sdd.getFullYear(), 
       month1 = sdd.getMonth() < 10 ? '0' + sdd.getMonth() : sdd.getMonth(), 
       day1  = sdd.getDate() < 10 ? '0' + sdd.getDate() : sdd.getDate(), 
       sd = day1 + '-' + month1 + '-' + yr1; 

       var edd=new Date(item.end_date); 
       yr2  = edd.getFullYear(), 
       month2 = edd.getMonth() < 10 ? '0' + edd.getMonth() : edd.getMonth(), 
       day2  = edd.getDate() < 10 ? '0' + edd.getDate() : edd.getDate(), 
       ed = day2 + '-' + month2 + '-' + yr2; 

       if(item.is_going==1) 
       { 

       if(k==0) 
       { 

       var start = new Date(item.start_date); 
       var end = new Date(item.end_date); 
       var diff = new Date(end - start); 
       var days = diff/1000/60/60/24; 


       $(".modal-body #ate").append('<div class="form-group row" style="padding-left:17%;margin-bottom: 0px;height: 30px;"><label class="form-control-label"for="l0"><h5>CME Name:</h5></label><label class="form-control-label"for="l0"><h5>'+item.cme_name+'</h5></label><label class="form-control-label"for="l0" style="padding-left:10%"><h5>CME Code:</h5></label><label class="form-control-label"for="l0"><h5>'+item.cme_code+'</h5></label></div><div class="form-group row" style="padding-left:30%;height: 20px;"><label class="form-control-label" for="l0"><h5>From</h5> </label><label class="form-control-label"for="l0"><h5>'+sd+'</h5></label><label class="form-control-label" for="l0"><h5>To</h5></label><label class="form-control-label"for="l0"><h5>'+ed+'</h5></label></div>'); 
       k++; 
       } 


        table.row.add([item.council_code+item.application_year+item.application_number,newDate ,item.user_name,item.mobile_no,'<select class="form-control" id="present'+j+'><option value="0">Ab</option><option value="1">P</option></select>']).draw(); 

       } 


       }); 
      } 
     }, 
     complete: function(){ 

     } 
    }); 

} 

在這上面的代碼。

+0

請幫助.... –

+0

發表您的完整代碼,請 –

+0

這是我的完整代碼 –

回答

0

這裏是解決方案:

$("#myTable tr").each(function(index){ 
     $(this).append("<td>test</td>"); 
    }); 
+0

這是在數據表中不可能 –

+0

您可以嘗試這也是工作數據表。 –

+0

現在我正在測試數據表插件中的代碼,這對我很有用。 –