One line of JS code! Implement a concise table __js

Source: Internet
Author: User

Monday School, back to make-up of logistics, sad reminders of life.

Nonsense not to say, directly on the code, well, 4 line, but the discerning can see it is a line.

var mytable=new Table ({
    title: ' University four years ',
    data:data,
    thead:thead
});

Data format with EXT

var data=[
	    
		[' sad ', ' eat ', ' sleep ', ' play games ', ' Learn Java ', ' See the World Cold ',
		[' sad ', ' eat ', ' sleep ', ' play games ', ' Learn Java ', ' See the world Cold '],
		[' sad ', ' Eat ', ' sleep ', ' play games ', ' Learn Java ', ' See the World Cold ',
		[' sad ', ' eat ', ' sleep ', ' play games ', ' Learn Java ', ' See the World Cold ']
	]
var thead=[' title 1 ', ' Title 2 ', ' Heading 3 ', ' Heading 4 ', ' Heading 5 ', ' Heading 6 '


Of course, every time you want to create such a table, you need to carry out a certain package, code as follows, write very random, not careful, no comments, there is no fault-tolerant processing, make it.

Obviously imitate the Ext table.

 
 
myext={};
myext.util={};
myext.util.css={};
		Myext.util.css.applycss=function (src) {var link=document.createelement (' link ') link.rel= "stylesheet";
		Link.type= ' Text/css ';
		LINK.HREF=SRC;
document.getElementsByTagName (' head ') [0].appendchild (link);
	
};
		function Table (config) {this.title=config.title;
		This.data=config.data;
		This.thead=config.thead;
This.show ();
    } table.prototype.show=function () {var table=document.createelement (' Table ');
    var tbody=document.createelement (' tbody ');
    var cap=document.createelement (' caption ');
    Cap.appendchild (document.createTextNode (this.title));
    Table.appendchild (CAP);
    Table.appendchild (TBODY);
    var thead=document.createelement (' tr ');
    Tbody.appendchild (THEAD);
    for (Var m=0;this.thead[m];m++) {var th=document.createelement (' th ');
    Th.appendchild (document.createTextNode (this.thead[m));
Thead.appendchild (TH);
		} var Rows=this.data.length;
		var cols=this.data[0].length;   
		for (Var i=0;i<rows;i++) {		var tr=document.createelement (' tr ');
			Tbody.appendchild (TR);
				    for (Var j=0;j<cols;j++) {if (j) {var td=document.createelement (' TD ');
			        Td.appendchild (document.createTextNode (this.data[i][j));
				Tr.appendchild (TD);
				    }else{var td=document.createelement (' th ');
			        Td.appendchild (document.createTextNode (this.data[i][j));
				Tr.appendchild (TD);
		}} myExt.util.css.applyCss (' Table.css ');
	Document.body.appendChild (table); var data=[[' sad ', ' eat ', ' sleep ', ' play games ', ' Learn Java ', ' See the World cold ', [' sad ', ' eat ', ' sleep ', ' play games ', ' Learn Java ', ' See the world Cold '], [' sad ', ' eat ', ' Sleep ', ' play games ', ' Learn Java ', ' See the World cold ', [' sad ', ' eat ', ' sleep ', ' play games ', ' Learn Java ', ' See the world Cold ']] var thead=[' title 1 ', ' Heading 2 ', ' Heading 3 ', ' Heading 4 ', ' Heading 5 ', ' Title 6 '] var mytable=new Table ({title: ' University four years ', Data:data, thead:thead});

Finally send everyone a pure JS canvas pie chart, forget Flash.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.