Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Some old notes on the datatables sorting issue
This may or may not work due to be some old code snippets
## SMW core
SMWQuery requires sorting parameter export such as:
+ // Add sorting array
+ foreach ( $this->sortkeys as $key => $order ) {
+ if ( $key !== '' ) {
+ $serialized['parameters']['sort'][] = str_replace( '_', ' ', $key );
+ $serialized['parameters']['order'][] = $order;
+ }
+ }
## Datatables js-source
@@ -217,17 +217,31 @@
return { 'aaData': aaData };
}
// Create column definitions (see aoColumnDefs)
// @see http://www.datatables.net/usage/columns
+ var sort = [];
+ if ( data.query.ask.parameters.sort !== undefined ) {
+ sort = data.query.ask.parameters.sort ;
+ }
+
var aoColumnDefs = [];
$.map ( data.query.result.printrequests, function( property, index ) {
+ var order = '';
+ if ( sort.length > 0 ) {
+ var sortI = $.inArray( property.label, sort );
+ order = data.query.ask.parameters.order[sortI];
+ }
+
+console.log( order );
+
aoColumnDefs.push( {
'mData': property.label,
'sTitle': property.label,
'sClass': 'smwtype' + property.typeid,
- 'aTargets': [index]
+ 'aTargets': [index],
+ 'asSorting': order ? [order] : ['asc','desc']
} );
} );
data.aoColumnDefs = aoColumnDefs;
// Parse and return results
@@ -589,11 +603,11 @@
) );
// Parse JS array and merge with the data array
$.extend( data, _datatables.parse.results( context, data ) );
if ( data.aaData.length > 0 ){
//@note Do something here
}
@@ -603,10 +617,11 @@
'sDom': sDom,
'sPaginationType': context.data( 'theme' ) === 'bootstrap' ? 'bootstrap' : 'full_numbers',
'bAutoWidth': false,
'oLanguage': _datatables.oLanguage,
'aaData': data.aaData,
+ 'bSort': true,
'aoColumnDefs': data.aoColumnDefs
} );
// Bind the imageInfo trigger and update the appropriate table cell
context.on( 'srf.datatables.afterImageInfoFetch', function( event, handler ) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.