Create Subrows dynamically inside a row in html table using javascript -
click view image of table refference
here creating rows dynamically using javascript. per requirements shown in above image (click above link view image), need create subrows within row, along row creation. these subrows should appear each row created dynamically. have used javascript create rows dynamically , have used rowspan , colspan attributes generate subrows "newcell.rowspan" (shown in below javascript code) not working. please guide me going wrong code.
i have provided image of table should like. advance thanks!
function display(){ var tableref = document.getelementbyid('mytable1').getelementsbytagname('tbody')[0]; var rowsadd = tableref.insertrow(tableref.rows.length); // var m = moment().format('yyyy-mm-dd h:mm a'); var newcell = rowsadd.insertcell(); newcell.innerhtml="<tr><td><input form ='forma' class= 'form-control input-sm' type='text' id = 'time' name= 'time' required> </td></tr>"; newcell.rowspan='7'; newcell = rowsadd.insertcell(); newcell.innerhtml="<tr><td><input form ='forma' class= 'form-control input-sm' id = 'oraltype' name= 'oraltype' required></td></tr>"; newcell.rowspan='7'; newcell = rowsadd.insertcell(); newcell.innerhtml="<tr><td ><input form ='forma' class= 'form-control input-sm' type='text' id = 'oralamt' name= 'oralamt' required ></td></tr>"; newcell.rowspan='7'; newcell = rowsadd.insertcell(); newcell.innerhtml="<tr><td width ='';><input form ='forma' class= 'form-control input-sm' id = 'oralcommence' name= 'oralcommence' required></td></tr>"; newcell.rowspan='7'; newcell = rowsadd.insertcell(); newcell.innerhtml="<tr><td width ='';><input form ='forma' class= 'form-control input-sm' ' id = 'amtgiv' name= 'amtgiv' required></td></tr>"; newcell.rowspan='7'; newcell = rowsadd.insertcell(); newcell.innerhtml="<tr><td><input form ='forma' class= 'form-control input-sm' type='text' id = 'urine' name= 'urine' required> </td></tr>"; newcell.rowspan='7'; newcell = rowsadd.insertcell(); newcell.innerhtml="<tr><td><input form ='forma' class= 'form-control input-sm' id = 'vomitus' name= 'vomitus' required></td></tr>"; newcell.rowspan='7'; newcell = rowsadd.insertcell(); newcell.innerhtml="<tr><td width ='';><input form ='forma' class= 'form-control input-sm' type='text' id = 'remarks' name= 'remarks' required ></td></tr>"; newcell.colspan='14'; newcell = rowsadd.insertcell(); newcell.innerhtml="<tr><td width ='';><input form ='forma' class= 'form-control input-sm' type='text' id = 'remarks' name= 'remarks' required ></td></tr>"; newcell.rowspan='7'; newcell = rowsadd.insertcell(); newcell.innerhtml="<tr><td><i class='fa fa-trash-o' style='font-size:20px' onclick='deleterow(this)'></i></td></tr>"; newcell.rowspan='7'; }
#mytable1 { border-collapse: collapse; width: 100%; } #mytable1 th { background-color: #009999; color: black; width : 180px; } .table-fixed{ } #mytable1 .tbody1{ height:200px; overflow-y:auto; } #mytable1 thead,.tbody1{ display:block; }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.6.3/css/bootstrap-select.min.css" /> <table class="table table-striped table-bordered table-fixed table-hover table-condensed" style="width: 1000px; " id="mytable1"> <thead> <tr> <th rowspan = '2' style="width:100px;">date comm.</th> <th rowspan='2' style="width:100px;">drug</th> <th rowspan='2' style="width:100px;">dosage</th> <th rowspan='2'style="width:100px;">route of admin</th> <th rowspan='2' style="width:100px;">ordered by</th> <th rowspan='2' style="width:100px;">time</th> <th colspan ='14' style="width:300px;">dosage variation</th> <th rowspan='2' style="width:100px;">remarks</th> <th rowspan='2' style="width:50px;">delete</th> </tr> <tr> <th>1</th> <th>2</th> <th>3</th> <th>4</th> <th>5</th> <th>6</th> <th>7</th> <th>8</th> <th>9</th> <th>10</th> <th>11</th> <th>12</th> <th>13</th> <th>14</th> </tr> </thead> <tbody class="tbody1"> </tbody> <tr id="hiderow"> <td><button onclick="display()" >add</button></td> </tr> </table>
Comments
Post a Comment