jqwidgets-framework
Version:
jQWidgets is an advanced Angular, Vue, Blazor, React, Web Components, jquery, ASP .NET MVC, Custom Elements and HTML5 UI framework.
98 lines (91 loc) • 4 kB
HTML
<html lang="en">
<head>
<title id='Description'>This example shows how to bind the jqxDataAdapter to JSON.</title>
<link rel="stylesheet" href="../../../jqwidgets/styles/jqx.base.css" type="text/css" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1 maximum-scale=1 minimum-scale=1" />
<script type="text/javascript" src="../../../scripts/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="../../../jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="../../../jqwidgets/jqxdata.js"></script>
<style type="text/css">
table {
font-family: verdana,arial,sans-serif;
font-size: 11px;
color: #333333;
border-width: 1px;
border-color: #666666;
border-collapse: collapse;
}
table th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #dedede;
}
table td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #ffffff;
}
</style>
<script type="text/javascript">
$(document).ready(function () {
var url = "../../sampledata/beverages.txt";
// prepare the data
var source =
{
datatype: "json",
datafields: [
{ name: 'name', type: 'string' },
{ name: 'type', type: 'string' },
{ name: 'calories', type: 'int' },
{ name: 'totalfat', type: 'string' },
{ name: 'protein', type: 'string' }
],
id: 'id',
url: url
};
var dataAdapter = new $.jqx.dataAdapter(source, {
loadComplete: function (records) {
// get data records.
var records = dataAdapter.records;
// get the length of the records array.
var length = records.length;
// loop through the records and display them in a table.
var html = "<table border='1'><tr><th align='left'>Name</th><th align='left'>Type</th><th align='left'>Calories</th><th align='right'>Total Fat</th><th align='left'>Protein</th></tr>";
for (var i = 0; i < 20; i++) {
var record = records[i];
html += "<tr>";
html += "<td>" + record.name + "</td>";
html += "<td>" + record.type + "</td>";
html += "<td>" + record.calories + "</td>";
html += "<td>" + record.totalfat + "</td>";
html += "<td>" + record.protein + "</td>";
html += "</tr>";
}
html += "</table>";
$("#table").html(html);
},
loadError: function (jqXHR, status, error) {
},
beforeLoadComplete: function (records) {
}
});
// perform data binding.
dataAdapter.dataBind();
});
</script>
</head>
<body class='default'>
<div id="table">
Loading...
</div>
<div style="position: absolute; bottom: 5px; right: 5px;">
<a href="https://www.jqwidgets.com/" alt="https://www.jqwidgets.com/"><img alt="https://www.jqwidgets.com/" title="https://www.jqwidgets.com/" src="https://www.jqwidgets.com/wp-content/design/i/logo-jqwidgets.png"/></a>
</div>
</body>
</html>