<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script rel="stylesheet" href="http://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css"></script>
</head>
<body>
<div id="ResultDiv" style="border: 2px;padding: 20px;">
<table style="padding: 10px;" id="table_id" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Region</th>
<th>Country</th>
<th>Population</th>
<th>Area</th>
<th>Pop_Density</th>
<th>Coastline</th>
<th>Net_migration</th>
<th>Infant_mortality</th>
<th>GDP</th>
<th>Literacy</th>
<th>Phones</th>
<th>Arable</th>
<th>Crops</th>
<th>Other</th>
<th>Climate</th>
<th>Birthrate</th>
<th>Deathrate</th>
<th>Agriculture</th>
<th>Industry</th>
<th>Service</th>
</tr>
</thead>
<TBODY><TD></TD></TBODY>
<tfoot> </tfoot>
</table>
</div>
<script type="text/javascript">
$( document ).ready(function() {
readListItem();
});
function readListItem()
{
debugger;
var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('world')/items?$select=Region,Country,Population,Area,Pop_Density,Coastline,Net_migration,Infant_mortality,GDP,Literacy,Phones,Arable,Crops,Other,Climate,Birthrate,Deathrate,Agriculture,Industry,Service";
$.ajax({
url: url,
method: 'GET',
headers: {
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"IF-MATCH": "*",
"X-HTTP-Method": null
},
success: function(data) {
debugger;
alert('success');
var dataTableExample = $('#table_id').DataTable();
if (dataTableExample != 'undefined')
{
dataTableExample.destroy();
}
dataTableExample = $('#table_id').DataTable({
scrollY: 300,
"aaData": data.d.results,
"aoColumns": [
{
"mData": "Region"
},
{
"mData": "Country"
},
{
"mData": "Population"
},
{
"mData": "Area"
},
{
"mData": "Pop_Density"
},
{
"mData": "Coastline"
},
{
"mData": "Net_migration"
},
{
"mData": "Infant_mortality"
},
{
"mData": "GDP"
},
{
"mData": "Literacy"
},
{
"mData": "Phones"
},
{
"mData": "Arable"
},
{
"mData": "Crops"
},
{
"mData": "Other"
},
{
"mData": "Climate"
},
{
"mData": "Birthrate"
},
{
"mData": "Deathrate"
},
{
"mData": "Agriculture"
},
{
"mData": "Industry"
},
{
"mData": "Service"
}
]
});
},
success: function(data)
{
alert(JSON.stringify(data));
},
error: function(error)
{
alert(JSON.stringify(error));
}
});
}
</script>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script rel="stylesheet" href="http://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css"></script>
</head>
<body>
<div id="ResultDiv" style="border: 2px;padding: 20px;">
<table style="padding: 10px;" id="table_id" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Region</th>
<th>Country</th>
<th>Population</th>
<th>Area</th>
<th>Pop_Density</th>
<th>Coastline</th>
<th>Net_migration</th>
<th>Infant_mortality</th>
<th>GDP</th>
<th>Literacy</th>
<th>Phones</th>
<th>Arable</th>
<th>Crops</th>
<th>Other</th>
<th>Climate</th>
<th>Birthrate</th>
<th>Deathrate</th>
<th>Agriculture</th>
<th>Industry</th>
<th>Service</th>
</tr>
</thead>
<TBODY><TD></TD></TBODY>
<tfoot> </tfoot>
</table>
</div>
<script type="text/javascript">
$( document ).ready(function() {
readListItem();
});
function readListItem()
{
debugger;
var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('world')/items?$select=Region,Country,Population,Area,Pop_Density,Coastline,Net_migration,Infant_mortality,GDP,Literacy,Phones,Arable,Crops,Other,Climate,Birthrate,Deathrate,Agriculture,Industry,Service";
$.ajax({
url: url,
method: 'GET',
headers: {
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"IF-MATCH": "*",
"X-HTTP-Method": null
},
success: function(data) {
debugger;
alert('success');
var dataTableExample = $('#table_id').DataTable();
if (dataTableExample != 'undefined')
{
dataTableExample.destroy();
}
dataTableExample = $('#table_id').DataTable({
scrollY: 300,
"aaData": data.d.results,
"aoColumns": [
{
"mData": "Region"
},
{
"mData": "Country"
},
{
"mData": "Population"
},
{
"mData": "Area"
},
{
"mData": "Pop_Density"
},
{
"mData": "Coastline"
},
{
"mData": "Net_migration"
},
{
"mData": "Infant_mortality"
},
{
"mData": "GDP"
},
{
"mData": "Literacy"
},
{
"mData": "Phones"
},
{
"mData": "Arable"
},
{
"mData": "Crops"
},
{
"mData": "Other"
},
{
"mData": "Climate"
},
{
"mData": "Birthrate"
},
{
"mData": "Deathrate"
},
{
"mData": "Agriculture"
},
{
"mData": "Industry"
},
{
"mData": "Service"
}
]
});
},
success: function(data)
{
alert(JSON.stringify(data));
},
error: function(error)
{
alert(JSON.stringify(error));
}
});
}
</script>
</body>
</html>