datatable supports offset/limit server side fetching of table data. js events are added onto each row. need to fix ordering, searching.
This commit is contained in:
parent
057b1a08a6
commit
a0ecbecf3b
10 changed files with 108 additions and 294 deletions
|
@ -39,6 +39,7 @@ function deletePlaylist(json) {
|
|||
}
|
||||
|
||||
function addLibraryItemEvents() {
|
||||
|
||||
$('#library_display tr[id ^= "au"]')
|
||||
.draggable({
|
||||
helper: 'clone'
|
||||
|
@ -52,37 +53,44 @@ function addLibraryItemEvents() {
|
|||
|
||||
}
|
||||
|
||||
function setLibraryContents(data){
|
||||
$("#library_display tr:not(:first-child)").remove();
|
||||
$("#library_display").append(data);
|
||||
function dtRowCallback( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
|
||||
var id = aData[6].substring(0,2) + "_" + aData[0];
|
||||
|
||||
addLibraryItemEvents()
|
||||
$(nRow).attr("id", id);
|
||||
|
||||
return nRow;
|
||||
}
|
||||
|
||||
function dtDrawCallback() {
|
||||
addLibraryItemEvents();
|
||||
}
|
||||
|
||||
function setUpLibrary() {
|
||||
|
||||
$("#library_display tr:first-child span.title").data({'ob': 'dc:title', 'order' : 'asc'});
|
||||
$("#library_display tr:first-child span.artist").data({'ob': 'dc:creator', 'order' : 'desc'});
|
||||
$("#library_display tr:first-child span.album").data({'ob': 'dc:source', 'order' : 'asc'});
|
||||
$("#library_display tr:first-child span.track").data({'ob': 'ls:track_num', 'order' : 'asc'});
|
||||
$("#library_display tr:first-child span.length").data({'ob': 'dcterms:extent', 'order' : 'asc'});
|
||||
$("#library_display tr:first-child span.type").data({'ob': 'dcterms:extent', 'order' : 'asc'});
|
||||
$('#library_display').dataTable( {
|
||||
"bProcessing": true,
|
||||
"bServerSide": true,
|
||||
"sAjaxSource": "/Library/contents/format/json",
|
||||
"fnServerData": function ( sSource, aoData, fnCallback ) {
|
||||
$.ajax( {
|
||||
"dataType": 'json',
|
||||
"type": "POST",
|
||||
"url": sSource,
|
||||
"data": aoData,
|
||||
"success": fnCallback
|
||||
} );
|
||||
},
|
||||
"fnRowCallback": dtRowCallback,
|
||||
"fnDrawCallback": dtDrawCallback,
|
||||
"aoColumns": [
|
||||
/* Id */ { "sName": "id", "bSearchable": false, "bVisible": false },
|
||||
/* Title */ { "sName": "track_title" },
|
||||
/* Creator */ { "sName": "artist_name" },
|
||||
/* Album */ { "sName": "album_title" },
|
||||
/* Track */ { "sName": "track_number" },
|
||||
/* Length */ { "sName": "length" },
|
||||
/* Type */ { "sName": "type" }
|
||||
]
|
||||
|
||||
$("#library_display tr:first-child span").click(function(){
|
||||
var url = "/Library/contents/format/html",
|
||||
ob = $(this).data('ob'),
|
||||
order = $(this).data('order');
|
||||
|
||||
//toggle order for next click.
|
||||
if(order === 'asc') {
|
||||
$(this).data('order', 'desc');
|
||||
}
|
||||
else {
|
||||
$(this).data('order', 'asc');
|
||||
}
|
||||
|
||||
$.post(url, {ob: ob, order: order}, setLibraryContents);
|
||||
});
|
||||
|
||||
addLibraryItemEvents()
|
||||
} );
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue