I have dynamically created bootstrap table and want to have my tbody scrollable while keeping head fixed but I am not able to do it. I want to do this with css. As I am creating the table dynamically, it is different from creating table using html , as I am using jquery . I want answer according to my code as I am not able to apply other answers regarding these type of question.
Here is the code with less table content-
var table = $("<table class='table'>");
table.append($("<thead><tr><th scope='col'>col1</th><th scope='col'>col2</th><th scope='col'>col3</th><th scope='col'>col4</th><th scope='col'>col5</th></tr><thead/>"));
for (var j = 0; j < 2; j++) {
var row = $('<tbody><tr class="parent_row" >' + '<td>' + "1" + '</td>' + '<td>' + "2" + '</td>' + '<td>' + "3" + '</td>' + '<td>' + "" + '</td>' + '<td>' + "" + '</td></tr><tbody/>');
table.append(row);
//child row
for (var i = 0; i < 2; i++) {
var row = $('<tr style="display: none">' + '<td>' + "" + '</td>' + '<td>' + "" + '</td>' + '<td>' + "" + '</td>' + '<td>' + "4" + '</td>' + '<td>' + "5" + '</td></tr>');
table.append(row);
$("#table").html(table);
$("#table").show();
$('.parent_row').on("click", function(e) {
e.preventDefault();
$(this).closest('.parent_row').nextUntil('.parent_row').toggle();
})
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="table">
</table>