Skip to content

Instantly share code, notes, and snippets.

@pujie
Created April 1, 2011 10:00
Show Gist options
  • Save pujie/897963 to your computer and use it in GitHub Desktop.
Save pujie/897963 to your computer and use it in GitHub Desktop.
vhgrid
<html>
<head>
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="vhgrid.main.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#mybutton").click(function(){
$("#mytable").createTable();
});
$("#addrow").click(function(){
$("#mytable").addRow("zzdz");
});
$("#addHeader").click(function(){
$("#mytable").addHeader(['COL 1','COL 2','COL 3','COL 4','COL 5','COL 6']);
});
$("#addMultiColumn").click(function(){
$("#mytable").addMultiColumn(['satu','dua','tiga','empat','lima','enam']);
});
$("#removeFirstrow").click(function(){
$("#mytable").removeFirstRow();
});
$("#removeLastrow").click(function(){
$("#mytable").removeLastRow();
});
});
</script>
</head>
<body>
<div id="mybutton">button</div>
<div id="addrow">addrow</div>
<div id="addHeader">addHeader</div>
<div id="addMultiColumn">addMultiColumn</div>
<div id="removeFirstrow">removeFirstrow</div>
<div id="removeLastrow">removeLastrow</div>
<div id="mytable"></div>
</body>
</html>
jQuery.fn.createTable = function(){
return this.each(function(){
$(this).html("<table><thead></thead><tbody></tbody></table>");
});
}
jQuery.fn.addHeader = function(param){
return this.each(function(){
var head = "<tr>";
jQuery.each(param,function(i,val){
head += "<th>"+val+"</th>";
});
head += "</tr>";
$(this).find("thead").append(head);
});
}
jQuery.fn.addMultiColumn = function(param){
return this.each(function(){
var row="<tr>";
jQuery.each(param,function(i,val){
row+="<td>"+val+"</td>";
});
row+="</tr>";
$(this).find("tbody").append(row);
});
}
jQuery.fn.addRow = function(param){
return this.each(function(){
$(this).find("tbody").append("<tr><td>" + param + "</td></tr>");
});
}
jQuery.fn.removeFirstRow = function(){
return this.each(function(){
$(this).find("tbody").find("tr").first().remove();
});
}
jQuery.fn.removeLastRow = function(){
return this.each(function(){
$(this).find("tbody").find("tr").last().remove();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment