Skip to content

Instantly share code, notes, and snippets.

@peterstadler
Last active January 26, 2022 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterstadler/1a4a455f9878ef9ad4c86384cc5b2454 to your computer and use it in GitHub Desktop.
Save peterstadler/1a4a455f9878ef9ad4c86384cc5b2454 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8"/>
<title>Übersicht des Bestands der Musikabteilung der Staatsbibliothek zu Berlin in der WeGA</title>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.3/css/jquery.dataTables.css"/>
<script type="text/javascript" charset="utf8" src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.js"></script>
</head>
<body>
<h1>Übersicht des Bestands der Musikabteilung der Staatsbibliothek zu Berlin in der WeGA</h1>
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>WeGA-ID</th>
<th>Verfasser</th>
<th>Datum</th>
<th>Titel</th>
<th>Signatur</th>
</tr>
</thead>
<tfoot>
<tr>
<th>WeGA-ID</th>
<th>Verfasser</th>
<th>Datum</th>
<th>Titel</th>
<th>Signatur</th>
</tr>
</tfoot>
</table>
<script>
$(document).ready(function() {
$('#example')
.on('xhr.dt', function ( e, settings, json, xhr ) {
// extract relevant headers and push them to our JSON object
json.recordsTotal = xhr.getResponseHeader('totalRecordCount')
json.recordsFiltered = xhr.getResponseHeader('filteredrecordcount')
} )
.DataTable( {
"processing": true,
"serverSide": true,
// searching is not yet supported by the API
"searching": false,
"ajax": {
// hard coded API endpoint and RISM sigel. This could be made dynamic …
url: "https://staging.weber-gesamtausgabe.de/api/v1/repositories/items?siglum=D-B",
cache: true,
dataSrc: '',
data: function(d) {
return {
// translate standard datatables parameters to WeGA URL parameter names
limit: d.length,
offset: d.start +1,
orderby: d.columns[d.order[0].column].name,
orderdir: d.order[0].dir
}
}
},
"columns": [
// translate WeGA API response to datatables columns
{ "data": "docID", "name": "docID", "orderable": true, "render": function(data, type, row, meta) { return '<a href="https://staging.weber-gesamtausgabe.de/' + data + '">' + data + '</a>'; } },
{ "data": "related_entities", "name": "author", "orderable": false, "render": function(data, type, row, meta) { var authors = []; data.forEach(function(item) { if(item.rel==='author') { authors.push( item.name ) }}); return authors.join('; ') } },
{ "data": "date", "name": "sortdate", "orderable": true },
{ "data": "title", "name": "title", "orderable": true },
{ "data": "idno", "name": "idno", "orderable": true }
]
} );
} );
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment