annotate DataTables-1.9.4/media/src/core/core.sort.js @ 7:0f2b740536fb draft

Uploaded
author saskia-hiltemann
date Mon, 21 Aug 2017 09:16:07 -0400
parents ac5f9272033b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2 * Change the order of the table
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
3 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
4 * @param {bool} bApplyClasses optional - should we apply classes or not
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
5 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
6 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
7 function _fnSort ( oSettings, bApplyClasses )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
8 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
9 var
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
10 i, iLen, j, jLen, k, kLen,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
11 sDataType, nTh,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
12 aaSort = [],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
13 aiOrig = [],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
14 oSort = DataTable.ext.oSort,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
15 aoData = oSettings.aoData,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
16 aoColumns = oSettings.aoColumns,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
17 oAria = oSettings.oLanguage.oAria;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
18
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
19 /* No sorting required if server-side or no sorting array */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
20 if ( !oSettings.oFeatures.bServerSide &&
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
21 (oSettings.aaSorting.length !== 0 || oSettings.aaSortingFixed !== null) )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
22 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
23 aaSort = ( oSettings.aaSortingFixed !== null ) ?
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
24 oSettings.aaSortingFixed.concat( oSettings.aaSorting ) :
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
25 oSettings.aaSorting.slice();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
26
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
27 /* If there is a sorting data type, and a function belonging to it, then we need to
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
28 * get the data from the developer's function and apply it for this column
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
29 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
30 for ( i=0 ; i<aaSort.length ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
31 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
32 var iColumn = aaSort[i][0];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
33 var iVisColumn = _fnColumnIndexToVisible( oSettings, iColumn );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
34 sDataType = oSettings.aoColumns[ iColumn ].sSortDataType;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
35 if ( DataTable.ext.afnSortData[sDataType] )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
36 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
37 var aData = DataTable.ext.afnSortData[sDataType].call(
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
38 oSettings.oInstance, oSettings, iColumn, iVisColumn
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
39 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
40 if ( aData.length === aoData.length )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
41 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
42 for ( j=0, jLen=aoData.length ; j<jLen ; j++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
43 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
44 _fnSetCellData( oSettings, j, iColumn, aData[j] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
45 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
46 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
47 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
48 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
49 _fnLog( oSettings, 0, "Returned data sort array (col "+iColumn+") is the wrong length" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
50 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
51 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
52 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
53
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
54 /* Create a value - key array of the current row positions such that we can use their
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
55 * current position during the sort, if values match, in order to perform stable sorting
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
56 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
57 for ( i=0, iLen=oSettings.aiDisplayMaster.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
58 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
59 aiOrig[ oSettings.aiDisplayMaster[i] ] = i;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
60 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
61
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
62 /* Build an internal data array which is specific to the sort, so we can get and prep
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
63 * the data to be sorted only once, rather than needing to do it every time the sorting
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
64 * function runs. This make the sorting function a very simple comparison
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
65 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
66 var iSortLen = aaSort.length;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
67 var fnSortFormat, aDataSort;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
68 for ( i=0, iLen=aoData.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
69 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
70 for ( j=0 ; j<iSortLen ; j++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
71 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
72 aDataSort = aoColumns[ aaSort[j][0] ].aDataSort;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
73
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
74 for ( k=0, kLen=aDataSort.length ; k<kLen ; k++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
75 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
76 sDataType = aoColumns[ aDataSort[k] ].sType;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
77 fnSortFormat = oSort[ (sDataType ? sDataType : 'string')+"-pre" ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
78
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
79 aoData[i]._aSortData[ aDataSort[k] ] = fnSortFormat ?
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
80 fnSortFormat( _fnGetCellData( oSettings, i, aDataSort[k], 'sort' ) ) :
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
81 _fnGetCellData( oSettings, i, aDataSort[k], 'sort' );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
82 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
83 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
84 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
85
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
86 /* Do the sort - here we want multi-column sorting based on a given data source (column)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
87 * and sorting function (from oSort) in a certain direction. It's reasonably complex to
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
88 * follow on it's own, but this is what we want (example two column sorting):
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
89 * fnLocalSorting = function(a,b){
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
90 * var iTest;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
91 * iTest = oSort['string-asc']('data11', 'data12');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
92 * if (iTest !== 0)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
93 * return iTest;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
94 * iTest = oSort['numeric-desc']('data21', 'data22');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
95 * if (iTest !== 0)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
96 * return iTest;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
97 * return oSort['numeric-asc']( aiOrig[a], aiOrig[b] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
98 * }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
99 * Basically we have a test for each sorting column, if the data in that column is equal,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
100 * test the next column. If all columns match, then we use a numeric sort on the row
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
101 * positions in the original data array to provide a stable sort.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
102 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
103 oSettings.aiDisplayMaster.sort( function ( a, b ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
104 var k, l, lLen, iTest, aDataSort, sDataType;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
105 for ( k=0 ; k<iSortLen ; k++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
106 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
107 aDataSort = aoColumns[ aaSort[k][0] ].aDataSort;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
108
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
109 for ( l=0, lLen=aDataSort.length ; l<lLen ; l++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
110 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
111 sDataType = aoColumns[ aDataSort[l] ].sType;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
112
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
113 iTest = oSort[ (sDataType ? sDataType : 'string')+"-"+aaSort[k][1] ](
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
114 aoData[a]._aSortData[ aDataSort[l] ],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
115 aoData[b]._aSortData[ aDataSort[l] ]
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
116 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
117
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
118 if ( iTest !== 0 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
119 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
120 return iTest;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
121 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
122 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
123 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
124
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
125 return oSort['numeric-asc']( aiOrig[a], aiOrig[b] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
126 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
127 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
128
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
129 /* Alter the sorting classes to take account of the changes */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
130 if ( (bApplyClasses === undefined || bApplyClasses) && !oSettings.oFeatures.bDeferRender )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
131 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
132 _fnSortingClasses( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
133 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
134
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
135 for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
136 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
137 var sTitle = aoColumns[i].sTitle.replace( /<.*?>/g, "" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
138 nTh = aoColumns[i].nTh;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
139 nTh.removeAttribute('aria-sort');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
140 nTh.removeAttribute('aria-label');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
141
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
142 /* In ARIA only the first sorting column can be marked as sorting - no multi-sort option */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
143 if ( aoColumns[i].bSortable )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
144 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
145 if ( aaSort.length > 0 && aaSort[0][0] == i )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
146 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
147 nTh.setAttribute('aria-sort', aaSort[0][1]=="asc" ? "ascending" : "descending" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
148
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
149 var nextSort = (aoColumns[i].asSorting[ aaSort[0][2]+1 ]) ?
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
150 aoColumns[i].asSorting[ aaSort[0][2]+1 ] : aoColumns[i].asSorting[0];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
151 nTh.setAttribute('aria-label', sTitle+
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
152 (nextSort=="asc" ? oAria.sSortAscending : oAria.sSortDescending) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
153 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
154 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
155 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
156 nTh.setAttribute('aria-label', sTitle+
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
157 (aoColumns[i].asSorting[0]=="asc" ? oAria.sSortAscending : oAria.sSortDescending) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
158 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
159 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
160 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
161 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
162 nTh.setAttribute('aria-label', sTitle);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
163 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
164 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
165
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
166 /* Tell the draw function that we have sorted the data */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
167 oSettings.bSorted = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
168 $(oSettings.oInstance).trigger('sort', oSettings);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
169
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
170 /* Copy the master data into the draw array and re-draw */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
171 if ( oSettings.oFeatures.bFilter )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
172 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
173 /* _fnFilter() will redraw the table for us */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
174 _fnFilterComplete( oSettings, oSettings.oPreviousSearch, 1 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
175 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
176 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
177 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
178 oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
179 oSettings._iDisplayStart = 0; /* reset display back to page 0 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
180 _fnCalculateEnd( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
181 _fnDraw( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
182 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
183 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
184
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
185
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
186 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
187 * Attach a sort handler (click) to a node
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
188 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
189 * @param {node} nNode node to attach the handler to
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
190 * @param {int} iDataIndex column sorting index
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
191 * @param {function} [fnCallback] callback function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
192 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
193 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
194 function _fnSortAttachListener ( oSettings, nNode, iDataIndex, fnCallback )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
195 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
196 _fnBindAction( nNode, {}, function (e) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
197 /* If the column is not sortable - don't to anything */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
198 if ( oSettings.aoColumns[iDataIndex].bSortable === false )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
199 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
200 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
201 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
202
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
203 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
204 * This is a little bit odd I admit... I declare a temporary function inside the scope of
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
205 * _fnBuildHead and the click handler in order that the code presented here can be used
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
206 * twice - once for when bProcessing is enabled, and another time for when it is
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
207 * disabled, as we need to perform slightly different actions.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
208 * Basically the issue here is that the Javascript engine in modern browsers don't
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
209 * appear to allow the rendering engine to update the display while it is still executing
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
210 * it's thread (well - it does but only after long intervals). This means that the
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
211 * 'processing' display doesn't appear for a table sort. To break the js thread up a bit
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
212 * I force an execution break by using setTimeout - but this breaks the expected
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
213 * thread continuation for the end-developer's point of view (their code would execute
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
214 * too early), so we only do it when we absolutely have to.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
215 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
216 var fnInnerSorting = function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
217 var iColumn, iNextSort;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
218
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
219 /* If the shift key is pressed then we are multiple column sorting */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
220 if ( e.shiftKey )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
221 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
222 /* Are we already doing some kind of sort on this column? */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
223 var bFound = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
224 for ( var i=0 ; i<oSettings.aaSorting.length ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
225 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
226 if ( oSettings.aaSorting[i][0] == iDataIndex )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
227 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
228 bFound = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
229 iColumn = oSettings.aaSorting[i][0];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
230 iNextSort = oSettings.aaSorting[i][2]+1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
231
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
232 if ( !oSettings.aoColumns[iColumn].asSorting[iNextSort] )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
233 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
234 /* Reached the end of the sorting options, remove from multi-col sort */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
235 oSettings.aaSorting.splice( i, 1 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
236 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
237 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
238 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
239 /* Move onto next sorting direction */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
240 oSettings.aaSorting[i][1] = oSettings.aoColumns[iColumn].asSorting[iNextSort];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
241 oSettings.aaSorting[i][2] = iNextSort;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
242 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
243 break;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
244 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
245 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
246
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
247 /* No sort yet - add it in */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
248 if ( bFound === false )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
249 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
250 oSettings.aaSorting.push( [ iDataIndex,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
251 oSettings.aoColumns[iDataIndex].asSorting[0], 0 ] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
252 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
253 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
254 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
255 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
256 /* If no shift key then single column sort */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
257 if ( oSettings.aaSorting.length == 1 && oSettings.aaSorting[0][0] == iDataIndex )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
258 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
259 iColumn = oSettings.aaSorting[0][0];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
260 iNextSort = oSettings.aaSorting[0][2]+1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
261 if ( !oSettings.aoColumns[iColumn].asSorting[iNextSort] )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
262 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
263 iNextSort = 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
264 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
265 oSettings.aaSorting[0][1] = oSettings.aoColumns[iColumn].asSorting[iNextSort];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
266 oSettings.aaSorting[0][2] = iNextSort;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
267 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
268 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
269 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
270 oSettings.aaSorting.splice( 0, oSettings.aaSorting.length );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
271 oSettings.aaSorting.push( [ iDataIndex,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
272 oSettings.aoColumns[iDataIndex].asSorting[0], 0 ] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
273 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
274 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
275
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
276 /* Run the sort */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
277 _fnSort( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
278 }; /* /fnInnerSorting */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
279
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
280 if ( !oSettings.oFeatures.bProcessing )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
281 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
282 fnInnerSorting();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
283 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
284 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
285 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
286 _fnProcessingDisplay( oSettings, true );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
287 setTimeout( function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
288 fnInnerSorting();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
289 if ( !oSettings.oFeatures.bServerSide )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
290 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
291 _fnProcessingDisplay( oSettings, false );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
292 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
293 }, 0 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
294 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
295
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
296 /* Call the user specified callback function - used for async user interaction */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
297 if ( typeof fnCallback == 'function' )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
298 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
299 fnCallback( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
300 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
301 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
302 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
303
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
304
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
305 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
306 * Set the sorting classes on the header, Note: it is safe to call this function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
307 * when bSort and bSortClasses are false
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
308 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
309 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
310 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
311 function _fnSortingClasses( oSettings )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
312 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
313 var i, iLen, j, jLen, iFound;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
314 var aaSort, sClass;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
315 var iColumns = oSettings.aoColumns.length;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
316 var oClasses = oSettings.oClasses;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
317
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
318 for ( i=0 ; i<iColumns ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
319 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
320 if ( oSettings.aoColumns[i].bSortable )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
321 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
322 $(oSettings.aoColumns[i].nTh).removeClass( oClasses.sSortAsc +" "+ oClasses.sSortDesc +
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
323 " "+ oSettings.aoColumns[i].sSortingClass );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
324 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
325 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
326
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
327 if ( oSettings.aaSortingFixed !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
328 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
329 aaSort = oSettings.aaSortingFixed.concat( oSettings.aaSorting );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
330 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
331 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
332 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
333 aaSort = oSettings.aaSorting.slice();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
334 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
335
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
336 /* Apply the required classes to the header */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
337 for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
338 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
339 if ( oSettings.aoColumns[i].bSortable )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
340 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
341 sClass = oSettings.aoColumns[i].sSortingClass;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
342 iFound = -1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
343 for ( j=0 ; j<aaSort.length ; j++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
344 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
345 if ( aaSort[j][0] == i )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
346 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
347 sClass = ( aaSort[j][1] == "asc" ) ?
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
348 oClasses.sSortAsc : oClasses.sSortDesc;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
349 iFound = j;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
350 break;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
351 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
352 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
353 $(oSettings.aoColumns[i].nTh).addClass( sClass );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
354
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
355 if ( oSettings.bJUI )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
356 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
357 /* jQuery UI uses extra markup */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
358 var jqSpan = $("span."+oClasses.sSortIcon, oSettings.aoColumns[i].nTh);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
359 jqSpan.removeClass(oClasses.sSortJUIAsc +" "+ oClasses.sSortJUIDesc +" "+
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
360 oClasses.sSortJUI +" "+ oClasses.sSortJUIAscAllowed +" "+ oClasses.sSortJUIDescAllowed );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
361
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
362 var sSpanClass;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
363 if ( iFound == -1 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
364 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
365 sSpanClass = oSettings.aoColumns[i].sSortingClassJUI;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
366 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
367 else if ( aaSort[iFound][1] == "asc" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
368 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
369 sSpanClass = oClasses.sSortJUIAsc;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
370 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
371 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
372 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
373 sSpanClass = oClasses.sSortJUIDesc;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
374 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
375
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
376 jqSpan.addClass( sSpanClass );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
377 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
378 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
379 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
380 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
381 /* No sorting on this column, so add the base class. This will have been assigned by
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
382 * _fnAddColumn
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
383 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
384 $(oSettings.aoColumns[i].nTh).addClass( oSettings.aoColumns[i].sSortingClass );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
385 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
386 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
387
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
388 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
389 * Apply the required classes to the table body
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
390 * Note that this is given as a feature switch since it can significantly slow down a sort
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
391 * on large data sets (adding and removing of classes is always slow at the best of times..)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
392 * Further to this, note that this code is admittedly fairly ugly. It could be made a lot
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
393 * simpler using jQuery selectors and add/removeClass, but that is significantly slower
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
394 * (on the order of 5 times slower) - hence the direct DOM manipulation here.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
395 * Note that for deferred drawing we do use jQuery - the reason being that taking the first
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
396 * row found to see if the whole column needs processed can miss classes since the first
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
397 * column might be new.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
398 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
399 sClass = oClasses.sSortColumn;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
400
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
401 if ( oSettings.oFeatures.bSort && oSettings.oFeatures.bSortClasses )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
402 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
403 var nTds = _fnGetTdNodes( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
404
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
405 /* Determine what the sorting class for each column should be */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
406 var iClass, iTargetCol;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
407 var asClasses = [];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
408 for (i = 0; i < iColumns; i++)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
409 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
410 asClasses.push("");
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
411 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
412 for (i = 0, iClass = 1; i < aaSort.length; i++)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
413 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
414 iTargetCol = parseInt( aaSort[i][0], 10 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
415 asClasses[iTargetCol] = sClass + iClass;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
416
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
417 if ( iClass < 3 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
418 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
419 iClass++;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
420 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
421 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
422
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
423 /* Make changes to the classes for each cell as needed */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
424 var reClass = new RegExp(sClass + "[123]");
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
425 var sTmpClass, sCurrentClass, sNewClass;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
426 for ( i=0, iLen=nTds.length; i<iLen; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
427 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
428 /* Determine which column we're looking at */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
429 iTargetCol = i % iColumns;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
430
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
431 /* What is the full list of classes now */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
432 sCurrentClass = nTds[i].className;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
433 /* What sorting class should be applied? */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
434 sNewClass = asClasses[iTargetCol];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
435 /* What would the new full list be if we did a replacement? */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
436 sTmpClass = sCurrentClass.replace(reClass, sNewClass);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
437
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
438 if ( sTmpClass != sCurrentClass )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
439 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
440 /* We changed something */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
441 nTds[i].className = $.trim( sTmpClass );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
442 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
443 else if ( sNewClass.length > 0 && sCurrentClass.indexOf(sNewClass) == -1 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
444 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
445 /* We need to add a class */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
446 nTds[i].className = sCurrentClass + " " + sNewClass;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
447 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
448 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
449 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
450 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
451