<%@ Page Language="C#" AutoEventWireup="true" CodeFile="jQueryTableJSONCSS.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css" >
table.gridtable {
font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 1px;
border-color: #666666;
border-collapse: collapse;
}
table.gridtable th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #dedede;
}
table.gridtable td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #ffffff;
}
</style>
<script src="jquery-1.9.1.js" type="text/javascript"></script>
<link href="jquery-1.10.2-ui.css" rel="stylesheet" type="text/css" />
<script src="jquery-1.10.2-ui.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(
function() {
alert('ads');
renderData();
}
);
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) {
var table = $('<table class="gridtable"></table>');
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) {
//alert(' name=' + key + ' value=' + p[key]);
cols.push(key);
}
return cols;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="Output">
</div>
</form>
</body>
</html>
No comments:
Post a Comment