How to do th, tr and td in pure Javascript

I want to use the bootgrid plugin.  The examples on net all use HTML for creating the table.  I want to use Javascript.  I am not sure how can I do something like
    <th data-column-id="id" data-identifier="true" data-type="numeric">ID</th> in Javascript.
Can someone help with this.  Thank you.

<table id="grid-command-buttons" class="table table-condensed table-hover table-striped bootgrid-table" aria-busy="false">
    <thead>
        <tr>
            <th data-column-id="id" data-identifier="true" data-type="numeric">ID</th>
            <th data-column-id="sender">Sender</th>
            <th data-column-id="received" data-order="desc">Received</th>
            <th data-column-id="commands" data-formatter="commands" data-sortable="false">Commands</th>
        </tr>                    
    </thead>
    <tbody>
        <tr>
            <td class="text-left">1122</td>
            <td class="text-left">scott@outlook.com</td>
            <td class="text-left">2014-10-27T07:23:43</td>
            <td class="text-left"></td>
        </tr>
        <tr>
            <td class="text-left">1123</td>
            <td class="text-left">scott@outlook.com</td>
            <td class="text-left">2014-10-27T07:23:43</td>
            <td class="text-left"></td>
        </tr>
        <tr>
            <td class="text-left">1124</td>
            <td class="text-left">scott@outlook.com</td>
            <td class="text-left">2014-10-27T07:23:43</td>
            <td class="text-left"></td>
        </tr>
    </tbody>
</table>

Open in new window

ambuliAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
You can find a good example at:
http://www.mysamplecode.com/2012/04/generate-html-table-using-javascript.html

To add attributes to the elements, use setAttribute():
https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute

Below is a modified version of that example that also includes a <THEAD> and adds a title attribute only to the first <th>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function addRow() {
          
    var myName = document.getElementById("name");
    var age = document.getElementById("age");
    var table = document.getElementById("myTableData");
 
    var rowCount = table.rows.length;
    var row = table.insertRow(rowCount);
 
    row.insertCell(0).innerHTML= '<input type="button" value = "Delete" onClick="Javacsript:deleteRow(this)">';
    row.insertCell(1).innerHTML= myName.value;
    row.insertCell(2).innerHTML= age.value;
 
}
 
function deleteRow(obj) {
      
    var index = obj.parentNode.parentNode.rowIndex;
    var table = document.getElementById("myTableData");
    table.deleteRow(index);
    
}
 
function addTable() {
      
    var myTableDiv = document.getElementById("myDynamicTable");
      
    var table = document.createElement('TABLE');
    table.border='1';
    
    var tableHead = document.createElement('THEAD');
    table.appendChild(tableHead);

    var tr = document.createElement('TR');
    tableHead.appendChild(tr);
	var th = document.createElement('TH');
	tr.appendChild(th);
	th.innerHTML="a";
	th.setAttribute("title","First Cell");
	
	var th = document.createElement('TH');
	tr.appendChild(th);
	th.innerHTML="b";

	var th = document.createElement('TH');
	tr.appendChild(th);
	th.innerHTML="c";
	
	var th = document.createElement('TH');
	tr.appendChild(th);
	th.innerHTML="d";

    var tableBody = document.createElement('TBODY');
    table.appendChild(tableBody);
      
    for (var i=0; i<3; i++){
       var tr = document.createElement('TR');
       tableBody.appendChild(tr);
       
       for (var j=0; j<4; j++){
           var td = document.createElement('TD');
           td.width='75';
           td.appendChild(document.createTextNode("Cell " + i + "," + j));
           tr.appendChild(td);
       }
    }
    myTableDiv.appendChild(table);
    
}
 
function load() {
    
    console.log("Page load finished");
 
}
</script>

</head>
<body>
<div id="myform">
<b>Simple form with name and age ...</b>
<table>
    <tr>
        <td>Name:</td>
        <td><input type="text" id="name"></td>
    </tr>
    <tr>
        <td>Age:</td>
        <td><input type="text" id="age">
        <input type="button" id="add" value="Add" onclick="Javascript:addRow()"></td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
    </tr>
</table>
</div>
<div id="mydata">
<b>Current data in the system ...</b>
<table id="myTableData"  border="1" cellpadding="2">
    <tr>
        <td>&nbsp;</td>
        <td><b>Name</b></td>
        <td><b>Age</b></td>
    </tr>
</table>
&nbsp;
 
</div>
<div id="myDynamicTable">
<input type="button" id="create" value="Click here" onclick="Javascript:addTable()">
to create a Table and add some data using JavaScript
</div>
</body>
</html>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.