1
0
mirror of https://github.com/DataTables/DataTables.git synced 2025-01-18 11:52:11 +01:00

New: aDataSort parameter for columns - this allows a column's sorting to take multiple columns into account when doing a sort. For example first name / last name columns make sense to do a multi-column sort. Previously in DataTables you would need to have the user do a multi-column sort themselves (with shift), but now you can define aDataSort (for example aDataSort: [ 0, 1 ]) to do effectively a multi column sort. Note that this is not shown to the end user that this was a multi-column sort in the same way that iDataSort wouldn't indicate that it could sort on a different column (if that was configured). Also note that iDataSort is still available for use and has not been modified externally, but if aDataSort is defined it will be given priority over any iDataSort parameter.

This commit is contained in:
Allan Jardine 2011-11-18 16:21:44 +00:00
parent edabb3febe
commit a1b33880c6

View File

@ -2541,7 +2541,7 @@
"sClass": null,
"fnRender": null,
"bUseRendered": true,
"iDataSort": iCol,
"aDataSort": [ iCol ],
"mDataProp": iCol,
"fnGetData": null,
"fnSetData": null,
@ -2612,12 +2612,20 @@
_fnMap( oCol, oOptions, "sClass" );
_fnMap( oCol, oOptions, "fnRender" );
_fnMap( oCol, oOptions, "bUseRendered" );
_fnMap( oCol, oOptions, "iDataSort" );
_fnMap( oCol, oOptions, "mDataProp" );
_fnMap( oCol, oOptions, "asSorting" );
_fnMap( oCol, oOptions, "sSortDataType" );
_fnMap( oCol, oOptions, "sDefaultContent" );
_fnMap( oCol, oOptions, "sContentPadding" );
/* iDataSort to be applied (backwards compatibility), but aDataSort will take
* priority if defined
*/
if ( typeof oOptions.iDataSort != 'undefined' )
{
oCol.aDataSort = [ oOptions.iDataSort ];
}
_fnMap( oCol, oOptions, "aDataSort" );
}
/* Cache the data get and set functions for speed */
@ -4641,7 +4649,6 @@
function _fnSort ( oSettings, bApplyClasses )
{
var
iDataSort, iDataType,
i, iLen, j, jLen,
aaSort = [],
aiOrig = [],
@ -4707,19 +4714,24 @@
*/
var iSortLen = aaSort.length;
oSettings.aiDisplayMaster.sort( function ( a, b ) {
var k, iTest, iDataSort, sDataType;
var k, l, lLen, iTest, aDataSort, sDataType;
for ( k=0 ; k<iSortLen ; k++ )
{
iDataSort = aoColumns[ aaSort[k][0] ].iDataSort;
sDataType = aoColumns[ iDataSort ].sType;
iTest = oSort[ (sDataType?sDataType:'string')+"-"+aaSort[k][1] ](
_fnGetCellData( oSettings, a, iDataSort, 'sort' ),
_fnGetCellData( oSettings, b, iDataSort, 'sort' )
);
if ( iTest !== 0 )
aDataSort = aoColumns[ aaSort[k][0] ].aDataSort;
for ( l=0, lLen=aDataSort.length ; l<lLen ; l++ )
{
return iTest;
sDataType = aoColumns[ aDataSort[l] ].sType;
iTest = oSort[ (sDataType ? sDataType : 'string')+"-"+aaSort[k][1] ](
_fnGetCellData( oSettings, a, aDataSort[l], 'sort' ),
_fnGetCellData( oSettings, b, aDataSort[l], 'sort' )
);
if ( iTest !== 0 )
{
return iTest;
}
}
}