mirror of
https://github.com/DataTables/DataTables.git
synced 2024-12-01 13:24:10 +01:00
Dev: Altering how sort classes are applied to be a draw callback
- Previously the sort classes were being applied at the end of the _fnSort function, with a callback for when using deferred rendering and server-side processing (that was a performance hit for deferred rendering thinging about it, since it hapened twice). - Now a single callback is used so sorting classes are applied only after the draw is done.
This commit is contained in:
parent
01444af1a6
commit
fd10532f94
@ -154,19 +154,7 @@ _fnCallbackReg( oSettings, 'aoFooterCallback', oInit.fnFooterCallback, 'u
|
||||
_fnCallbackReg( oSettings, 'aoInitComplete', oInit.fnInitComplete, 'user' );
|
||||
_fnCallbackReg( oSettings, 'aoPreDrawCallback', oInit.fnPreDrawCallback, 'user' );
|
||||
|
||||
if ( oSettings.oFeatures.bServerSide && oSettings.oFeatures.bSort &&
|
||||
oSettings.oFeatures.bSortClasses )
|
||||
{
|
||||
/* Enable sort classes for server-side processing. Safe to do it here, since server-side
|
||||
* processing must be enabled by the developer
|
||||
*/
|
||||
_fnCallbackReg( oSettings, 'aoDrawCallback', _fnSortingClasses, 'server_side_sort_classes' );
|
||||
}
|
||||
else if ( oSettings.oFeatures.bDeferRender )
|
||||
{
|
||||
_fnCallbackReg( oSettings, 'aoDrawCallback', _fnSortingClasses, 'defer_sort_classes' );
|
||||
}
|
||||
|
||||
// @todo Remove in 1.11
|
||||
if ( oInit.bJQueryUI )
|
||||
{
|
||||
/* Use the JUI classes object for display. You could clone the oStdClasses object if
|
||||
@ -338,6 +326,7 @@ if ( oInit.bStateSave )
|
||||
/*
|
||||
* Sorting
|
||||
* Check the aaSorting array
|
||||
* @todo For modularisation (1.11) this needs to do into a sort start up handler
|
||||
*/
|
||||
for ( i=0, iLen=oSettings.aaSorting.length ; i<iLen ; i++ )
|
||||
{
|
||||
@ -375,6 +364,26 @@ for ( i=0, iLen=oSettings.aaSorting.length ; i<iLen ; i++ )
|
||||
*/
|
||||
_fnSortingClasses( oSettings );
|
||||
|
||||
if ( oSettings.oFeatures.bSort )
|
||||
{
|
||||
_fnCallbackReg( oSettings, 'aoDrawCallback', function () {
|
||||
if ( oSettings.bSorted ) {
|
||||
var aSort = _fnSortFlatten( oSettings );
|
||||
var sortedColumns = {};
|
||||
|
||||
$.each( aSort, function (i, val) {
|
||||
sortedColumns[ val.col ] = val.dir;
|
||||
} );
|
||||
|
||||
$(oSettings.nTable).trigger('sort', [oSettings, aSort, sortedColumns]);
|
||||
|
||||
_fnSortingClasses( oSettings );
|
||||
_fnSortAria( oSettings );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Final init
|
||||
|
@ -35,14 +35,13 @@ function _fnSortFlatten ( settings )
|
||||
/**
|
||||
* Change the order of the table
|
||||
* @param {object} oSettings dataTables settings object
|
||||
* @param {bool} bApplyClasses optional - should we apply classes or not
|
||||
* @memberof DataTable#oApi
|
||||
* @todo This really needs split up!
|
||||
*/
|
||||
function _fnSort ( oSettings, bApplyClasses )
|
||||
function _fnSort ( oSettings )
|
||||
{
|
||||
var
|
||||
i, ien, iLen, j, jLen, k, kLen, sortedColumns={},
|
||||
i, ien, iLen, j, jLen, k, kLen,
|
||||
sDataType, nTh,
|
||||
aSort = [],
|
||||
aiOrig = [],
|
||||
@ -59,7 +58,6 @@ function _fnSort ( oSettings, bApplyClasses )
|
||||
|
||||
for ( i=0, ien=aSort.length ; i<ien ; i++ ) {
|
||||
sortCol = aSort[i];
|
||||
sortedColumns[ sortCol.col ] = sortCol.dir;
|
||||
|
||||
// Track if we can use the fast sort algorithm
|
||||
if ( sortCol.formatter ) {
|
||||
@ -156,17 +154,8 @@ function _fnSort ( oSettings, bApplyClasses )
|
||||
}
|
||||
}
|
||||
|
||||
/* Alter the sorting classes to take account of the changes */
|
||||
if ( (bApplyClasses === undefined || bApplyClasses) && !oSettings.oFeatures.bDeferRender )
|
||||
{
|
||||
_fnSortingClasses( oSettings );
|
||||
}
|
||||
|
||||
_fnSortAria( oSettings );
|
||||
|
||||
/* Tell the draw function that we have sorted the data */
|
||||
oSettings.bSorted = true;
|
||||
$(oSettings.nTable).trigger('sort', [oSettings, aSort, sortedColumns]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,6 +30,8 @@ $.extend( DataTable.ext.oStdClasses, {
|
||||
"sSortableDesc": "sorting_desc_disabled",
|
||||
"sSortableNone": "sorting_disabled",
|
||||
"sSortColumn": "sorting_", /* Note that an int is postfixed for the sorting order */
|
||||
|
||||
// Deprecated
|
||||
"sSortJUIAsc": "",
|
||||
"sSortJUIDesc": "",
|
||||
"sSortJUI": "",
|
||||
@ -49,6 +51,8 @@ $.extend( DataTable.ext.oStdClasses, {
|
||||
/* Misc */
|
||||
"sHeaderTH": "",
|
||||
"sFooterTH": "",
|
||||
|
||||
// Deprecated
|
||||
"sJUIHeader": "",
|
||||
"sJUIFooter": ""
|
||||
} );
|
||||
|
@ -8,7 +8,11 @@ $.extend( true, DataTable.ext.renderer, {
|
||||
// Attach a sort listener to update on sort
|
||||
$(settings.nTable).on( 'sort', function ( e, settings, sorting, columns ) {
|
||||
cell
|
||||
.removeClass( classes.sSortAsc +" "+classes.sSortDesc )
|
||||
.removeClass(
|
||||
column.sSortingClass +' '+
|
||||
classes.sSortAsc +' '+
|
||||
classes.sSortDesc
|
||||
)
|
||||
.addClass( columns[ idx ] == 'asc' ?
|
||||
classes.sSortAsc : columns[ idx ] == 'desc' ?
|
||||
classes.sSortDesc :
|
||||
|
Loading…
Reference in New Issue
Block a user