2017-04-11 75 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

现在我正在测试数据表插件中的代码,这对我很有用。 –