0
<html>
<head>
<title>Bootstrap Grid</title>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style type="text/css">

</style>
</head> 
<body>
<div class="container">
<div id="Output"></div>
</div>
<script>

$(document).ready(function($) {
    console.log('Document Ready');
    renderData();
    checkoutput();
});
function renderData() {
        var obj = { 'players': [
            { 'fname': 'joe', 'lname': 'smith', 'number': '34' },
            { 'fname': 'jim', 'lname': 'jones', 'number': '12' },
            { 'fname': 'jack', 'lname': 'Hoff', 'number': '84' } 
            ] };

        var cols = GetHeaders(obj); 

        $('#Output').html(CreateTable(obj, cols));
}



    function CreateTable(obj, cols) {
        // below bootstrap table is not effective
        var table = $('<table id="mytable" class="table table-bordered table-condensed table-striped table-hover"></table>');
        console.log('what is there' +table.text());
        var th = $('<tr></tr>');
        for (var i = 0; i < cols.length; i++) {
            th.append('<th>' + cols[i] + '</th>');
        }
        table.append(th);

        for (var j = 0; j < obj.players.length; j++) {
            var player = obj.players[j];
            var tr = $('<tr></tr>');
            for (var k = 0; k < cols.length; k++) {
                var columnName = cols[k];
                tr.append('<td>' + player[columnName] + '</td>');
            }
            table.append(tr);
        }
        return table;
    }

    function GetHeaders(obj) {
        var cols = new Array();
        var p = obj.players[0];
        for (var key in p) {
            cols.push(key);
        }
        return cols;
    }
    function checkoutput(){
    console.log('what is in the html');
    console.log($('#Output').html());
    }

</script>
</body>
</html>
2
  • 2
    is there a question? Commented Feb 15, 2017 at 1:27
  • Question is bootstrap class like table-bordered, table-condensed etc.. is not working .class="table table-bordered table-condensed table-striped table-hover" Commented Feb 15, 2017 at 7:43

2 Answers 2

1

<html>
<head>
<title>Bootstrap Grid</title>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style type="text/css">

</style>
</head> 
<body>
<div class="container">
<div id="Output"></div>
</div>
<script>

$(document).ready(function($) {
    console.log('Document Ready');
    renderData();
    checkoutput();
});
function renderData() {
        var obj = { 'players': [
            { 'fname': 'joe', 'lname': 'smith', 'number': '34' },
            { 'fname': 'jim', 'lname': 'jones', 'number': '12' },
            { 'fname': 'jack', 'lname': 'Hoff', 'number': '84' } 
            ] };

        var cols = GetHeaders(obj); 

        $('#Output').html(CreateTable(obj, cols));
}



    function CreateTable(obj, cols) {
        // below bootstrap table is not effective
        var table = $('<table id="mytable" class="table table-bordered table-condensed table-striped table-hover"></table>');
        console.log('what is there' +table.text());
        var th = $('<tr></tr>');
        for (var i = 0; i < cols.length; i++) {
            th.append('<th>' + cols[i] + '</th>');
        }
        table.append(th);

        for (var j = 0; j < obj.players.length; j++) {
            var player = obj.players[j];
            var tr = $('<tr></tr>');
            for (var k = 0; k < cols.length; k++) {
                var columnName = cols[k];
                tr.append('<td>' + player[columnName] + '</td>');
            }
            table.append(tr);
        }
        return table;
    }

    function GetHeaders(obj) {
        var cols = new Array();
        var p = obj.players[0];
        for (var key in p) {
            cols.push(key);
        }
        return cols;
    }
    function checkoutput(){
    console.log('what is in the html');
    console.log($('#Output').html());
    }

</script>
</body>
</html>

Your bootstrap css is working fine--

You can see bootstrap css is working from red bordered line.

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

class="table table-bordered table-condensed table-striped table-hover" - table-bordered table-condensed table-striped table-hover is not applied.. Am I missing some thing.
1

I got the answer. I have added <tbody></tbody>. After this all bootstrap class added related to table getting executed..

class="table table-bordered table-condensed table-striped table-hover"

var table = $('<table id="mytable" class="table table-bordered 
table-condensed table-striped table-hover"><tbody></tbody></table>');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.