简体   繁体   中英

Add dynamic column in same row in datatable

I want to create dynamic table column in same row in a datatable using loop. But I can't do this. Please help.. This is my code..

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

        }
    });

}

In this above code using for loop I want to add different select box with different id value in different column but in same row.

Here is the Solution :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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