繁体   English   中英

在数据表的同一行中添加动态列

[英]Add dynamic column in same row in datatable

我想使用循环在数据表的同一行中创建动态表列。 但是我做不到。 请帮助..这是我的代码..

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(){

        }
    });

}

在上述使用for循环的代码中,我想在不同的列但在同一行中添加具有不同id值的不同选择框。

这是解决方案:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM