Pages

Thursday, December 16, 2010

Javascript - JTable

/**
* Author: irfan.ub@gmail.com
* Date: Dec 16, 2010
* Version: 1.0
*
* This class provide you with table interface. You just need
* to provide the data in 2D arrays.
*
* @id string id that identified for element access
* @data 2dArray data that you supply for the table content
*/

function JTable(id,data){
 
    this.data = data;
    this.elem = document.getElementById(id);

    this.table = document.createElement('table');
    this.table.style.border = '1px solid #f5f';


    for(i=0;i<this.data.length;i++){

        this.tr = document.createElement('tr');

        for(j=0;j<this.data[i].length;j++){
            this.td = document.createElement('td');
            this.td.width = '100px';
            this.td.style.border = '1px solid #f5f';
            this.td.innerHTML = data[i][j];
            this.tr.appendChild(this.td);
        }

        this.table.appendChild(this.tr);
    }

    this.elem.appendChild(this.table); 
}

No comments:

Post a Comment