jquery-KivaSort cache
This example uses the ks_partnerData option to load local JSON (a portion of the data fetched from the Kiva API earlier) to populate the table. No AJAX call is made It also shows how to use the Datatables Buttons extension to display the two custom buttons provided by jquery-kivasort ("JSON" and "Reload").
by cristoper
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="//cdn.datatables.net/1.10.10/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="//cdn.datatables.net/buttons/1.1.0/css/buttons.dataTables.min.css">
<meta charset="utf-8">
<title>Kiva Sort</title>
</head>
<body>
<table id="KivaSort" class="display compact">
<thead>
<tr>
<th>Name</th>
<th>Portfolio Yield</th>
<th>Profitability</th>
<th>Country</th>
<th>Default Rate</th>
</tr>
</thead>
<tbody></tbody>
</table>
<script
src="//code.jquery.com/jquery-3.5.1.min.js"
integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
crossorigin="anonymous"></script>
<script src="//cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js"></script>
<script src="//cdn.datatables.net/buttons/1.1.0/js/dataTables.buttons.min.js"></script>
<script src="//cristoper.github.io/jquery-KivaSort/kiva_sort.js"></script>
</body>
</html>
JavaScript
$(document).ready(function () {
var table = $('#KivaSort');
table.makeKivaTable({
/* Use our cached data */
pageLength: 5,
buttons: ['pageLength', 'reload', 'json'],
dom: 'Bftip',
//scrollX: true,
/* Sort by Portfolio Yield, and then Profitability */
order: [[1, "desc"], [2, "desc"]],
ks_partnerData: {"paging":{"page":1,"total":357,"page_size":500,"pages":1},"partners":[{"id":1,"name":"East Africa Beta","status":"closed","rating":"0.0","due_diligence_type":"Full","image":{"id":58088,"template_id":1},"start_date":"2005-04-15T17:00:00Z","countries":[{"iso_code":"UG","region":"Africa","name":"Uganda","location":{"geo":{"level":"country","pairs":"2 33","type":"point"}}},{"iso_code":"KE","region":"Africa","name":"Kenya","location":{"geo":{"level":"country","pairs":"1 38","type":"point"}}},{"iso_code":"TZ","region":"Africa","name":"Tanzania","location":{"geo":{"level":"country","pairs":"-6 35","type":"point"}}}],"delinquency_rate":0,"default_rate":9.1917293233083,"total_amount_raised":26600,"loans_posted":62,"delinquency_rate_note":"","default_rate_note":"","portfolio_yield_note":"","charges_fees_and_interest":true,"average_loan_size_percent_per_capita_income":0,"loans_at_risk_rate":0,"currency_exchange_loss_rate":0},{"id":2,"name":"The Shurush Initiative","status":"closed","rating":"0.0","due_diligence_type":"Full","image":{"id":309,"template_id":1},"start_date":"2006-02-15T18:00:00Z","countries":[{"iso_code":"GZ","region":"Middle East","name":"Gaza","location":{"geo":{"level":"country","pairs":"31.5 34.466667","type":"point"}}}],"delinquency_rate":0,"default_rate":57.157727272727,"total_amount_raised":4400,"loans_posted":15,"delinquency_rate_note":"","default_rate_note":"","portfolio_yield_note":"Test Test \n<a href=\"http:\/\/www.google.com\">Visit...