annotate DataTables-1.9.4/media/src/core/core.columns.js @ 0:ac5f9272033b draft

first upload
author saskia-hiltemann
date Tue, 01 Jul 2014 11:42:23 -0400
parents
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
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
3 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
4 * Add a column to the list used for the table with default values
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
5 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
6 * @param {node} nTh The th element for this column
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
7 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
8 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
9 function _fnAddColumn( oSettings, nTh )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
10 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
11 var oDefaults = DataTable.defaults.columns;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
12 var iCol = oSettings.aoColumns.length;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
13 var oCol = $.extend( {}, DataTable.models.oColumn, oDefaults, {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
14 "sSortingClass": oSettings.oClasses.sSortable,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
15 "sSortingClassJUI": oSettings.oClasses.sSortJUI,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
16 "nTh": nTh ? nTh : document.createElement('th'),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
17 "sTitle": oDefaults.sTitle ? oDefaults.sTitle : nTh ? nTh.innerHTML : '',
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
18 "aDataSort": oDefaults.aDataSort ? oDefaults.aDataSort : [iCol],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
19 "mData": oDefaults.mData ? oDefaults.oDefaults : iCol
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
20 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
21 oSettings.aoColumns.push( oCol );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
22
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
23 /* Add a column specific filter */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
24 if ( oSettings.aoPreSearchCols[ iCol ] === undefined || oSettings.aoPreSearchCols[ iCol ] === null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
25 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
26 oSettings.aoPreSearchCols[ iCol ] = $.extend( {}, DataTable.models.oSearch );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
27 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
28 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
29 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
30 var oPre = oSettings.aoPreSearchCols[ iCol ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
31
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
32 /* Don't require that the user must specify bRegex, bSmart or bCaseInsensitive */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
33 if ( oPre.bRegex === undefined )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
34 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
35 oPre.bRegex = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
36 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
37
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
38 if ( oPre.bSmart === undefined )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
39 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
40 oPre.bSmart = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
41 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
42
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
43 if ( oPre.bCaseInsensitive === undefined )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
44 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
45 oPre.bCaseInsensitive = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
46 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
47 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
48
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
49 /* Use the column options function to initialise classes etc */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
50 _fnColumnOptions( oSettings, iCol, null );
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 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
55 * Apply options for a column
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
56 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
57 * @param {int} iCol column index to consider
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
58 * @param {object} oOptions object with sType, bVisible and bSearchable etc
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
59 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
60 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
61 function _fnColumnOptions( oSettings, iCol, oOptions )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
62 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
63 var oCol = oSettings.aoColumns[ iCol ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
64
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
65 /* User specified column options */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
66 if ( oOptions !== undefined && oOptions !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
67 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
68 /* Backwards compatibility for mDataProp */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
69 if ( oOptions.mDataProp && !oOptions.mData )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
70 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
71 oOptions.mData = oOptions.mDataProp;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
72 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
73
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
74 if ( oOptions.sType !== undefined )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
75 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
76 oCol.sType = oOptions.sType;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
77 oCol._bAutoType = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
78 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
79
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
80 $.extend( oCol, oOptions );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
81 _fnMap( oCol, oOptions, "sWidth", "sWidthOrig" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
82
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
83 /* iDataSort to be applied (backwards compatibility), but aDataSort will take
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
84 * priority if defined
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
85 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
86 if ( oOptions.iDataSort !== undefined )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
87 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
88 oCol.aDataSort = [ oOptions.iDataSort ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
89 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
90 _fnMap( oCol, oOptions, "aDataSort" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
91 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
92
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
93 /* Cache the data get and set functions for speed */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
94 var mRender = oCol.mRender ? _fnGetObjectDataFn( oCol.mRender ) : null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
95 var mData = _fnGetObjectDataFn( oCol.mData );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
96
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
97 oCol.fnGetData = function (oData, sSpecific) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
98 var innerData = mData( oData, sSpecific );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
99
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
100 if ( oCol.mRender && (sSpecific && sSpecific !== '') )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
101 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
102 return mRender( innerData, sSpecific, oData );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
103 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
104 return innerData;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
105 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
106 oCol.fnSetData = _fnSetObjectDataFn( oCol.mData );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
107
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
108 /* Feature sorting overrides column specific when off */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
109 if ( !oSettings.oFeatures.bSort )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
110 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
111 oCol.bSortable = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
112 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
113
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
114 /* Check that the class assignment is correct for sorting */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
115 if ( !oCol.bSortable ||
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
116 ($.inArray('asc', oCol.asSorting) == -1 && $.inArray('desc', oCol.asSorting) == -1) )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
117 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
118 oCol.sSortingClass = oSettings.oClasses.sSortableNone;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
119 oCol.sSortingClassJUI = "";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
120 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
121 else if ( $.inArray('asc', oCol.asSorting) == -1 && $.inArray('desc', oCol.asSorting) == -1 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
122 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
123 oCol.sSortingClass = oSettings.oClasses.sSortable;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
124 oCol.sSortingClassJUI = oSettings.oClasses.sSortJUI;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
125 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
126 else if ( $.inArray('asc', oCol.asSorting) != -1 && $.inArray('desc', oCol.asSorting) == -1 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
127 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
128 oCol.sSortingClass = oSettings.oClasses.sSortableAsc;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
129 oCol.sSortingClassJUI = oSettings.oClasses.sSortJUIAscAllowed;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
130 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
131 else if ( $.inArray('asc', oCol.asSorting) == -1 && $.inArray('desc', oCol.asSorting) != -1 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
132 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
133 oCol.sSortingClass = oSettings.oClasses.sSortableDesc;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
134 oCol.sSortingClassJUI = oSettings.oClasses.sSortJUIDescAllowed;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
135 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
136 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
137
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
138
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
139 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
140 * Adjust the table column widths for new data. Note: you would probably want to
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
141 * do a redraw after calling this function!
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
142 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
143 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
144 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
145 function _fnAdjustColumnSizing ( oSettings )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
146 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
147 /* Not interested in doing column width calculation if auto-width is disabled */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
148 if ( oSettings.oFeatures.bAutoWidth === false )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
149 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
150 return false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
151 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
152
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
153 _fnCalculateColumnWidths( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
154 for ( var i=0 , iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
155 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
156 oSettings.aoColumns[i].nTh.style.width = oSettings.aoColumns[i].sWidth;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
157 }
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
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
161 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
162 * Covert the index of a visible column to the index in the data array (take account
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
163 * of hidden columns)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
164 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
165 * @param {int} iMatch Visible column index to lookup
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
166 * @returns {int} i the data index
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
167 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
168 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
169 function _fnVisibleToColumnIndex( oSettings, iMatch )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
170 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
171 var aiVis = _fnGetColumns( oSettings, 'bVisible' );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
172
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
173 return typeof aiVis[iMatch] === 'number' ?
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
174 aiVis[iMatch] :
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
175 null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
176 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
177
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
178
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
179 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
180 * Covert the index of an index in the data array and convert it to the visible
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
181 * column index (take account of hidden columns)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
182 * @param {int} iMatch Column index to lookup
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
183 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
184 * @returns {int} i the data index
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
185 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
186 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
187 function _fnColumnIndexToVisible( oSettings, iMatch )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
188 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
189 var aiVis = _fnGetColumns( oSettings, 'bVisible' );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
190 var iPos = $.inArray( iMatch, aiVis );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
191
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
192 return iPos !== -1 ? iPos : null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
193 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
194
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
195
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
196 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
197 * Get the number of visible columns
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
198 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
199 * @returns {int} i the number of visible columns
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
200 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
201 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
202 function _fnVisbleColumns( oSettings )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
203 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
204 return _fnGetColumns( oSettings, 'bVisible' ).length;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
205 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
206
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
207
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
208 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
209 * Get an array of column indexes that match a given property
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
210 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
211 * @param {string} sParam Parameter in aoColumns to look for - typically
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
212 * bVisible or bSearchable
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
213 * @returns {array} Array of indexes with matched properties
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
214 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
215 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
216 function _fnGetColumns( oSettings, sParam )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
217 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
218 var a = [];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
219
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
220 $.map( oSettings.aoColumns, function(val, i) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
221 if ( val[sParam] ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
222 a.push( i );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
223 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
224 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
225
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
226 return a;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
227 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
228
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
229
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
230 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
231 * Get the sort type based on an input string
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
232 * @param {string} sData data we wish to know the type of
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
233 * @returns {string} type (defaults to 'string' if no type can be detected)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
234 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
235 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
236 function _fnDetectType( sData )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
237 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
238 var aTypes = DataTable.ext.aTypes;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
239 var iLen = aTypes.length;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
240
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
241 for ( var i=0 ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
242 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
243 var sType = aTypes[i]( sData );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
244 if ( sType !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
245 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
246 return sType;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
247 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
248 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
249
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
250 return 'string';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
251 }
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 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
255 * Figure out how to reorder a display list
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
256 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
257 * @returns array {int} aiReturn index list for reordering
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
258 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
259 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
260 function _fnReOrderIndex ( oSettings, sColumns )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
261 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
262 var aColumns = sColumns.split(',');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
263 var aiReturn = [];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
264
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
265 for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
266 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
267 for ( var j=0 ; j<iLen ; j++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
268 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
269 if ( oSettings.aoColumns[i].sName == aColumns[j] )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
270 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
271 aiReturn.push( j );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
272 break;
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
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
277 return aiReturn;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
278 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
279
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
280
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
281 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
282 * Get the column ordering that DataTables expects
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
283 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
284 * @returns {string} comma separated list of names
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
285 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
286 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
287 function _fnColumnOrdering ( oSettings )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
288 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
289 var sNames = '';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
290 for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
291 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
292 sNames += oSettings.aoColumns[i].sName+',';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
293 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
294 if ( sNames.length == iLen )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
295 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
296 return "";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
297 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
298 return sNames.slice(0, -1);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
299 }
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 * Take the column definitions and static columns arrays and calculate how
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
304 * they relate to column indexes. The callback function will then apply the
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
305 * definition found for a column to a suitable configuration object.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
306 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
307 * @param {array} aoColDefs The aoColumnDefs array that is to be applied
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
308 * @param {array} aoCols The aoColumns array that defines columns individually
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
309 * @param {function} fn Callback function - takes two parameters, the calculated
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
310 * column index and the definition for that column.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
311 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
312 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
313 function _fnApplyColumnDefs( oSettings, aoColDefs, aoCols, fn )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
314 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
315 var i, iLen, j, jLen, k, kLen;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
316
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
317 // Column definitions with aTargets
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
318 if ( aoColDefs )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
319 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
320 /* Loop over the definitions array - loop in reverse so first instance has priority */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
321 for ( i=aoColDefs.length-1 ; i>=0 ; i-- )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
322 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
323 /* Each definition can target multiple columns, as it is an array */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
324 var aTargets = aoColDefs[i].aTargets;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
325 if ( !$.isArray( aTargets ) )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
326 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
327 _fnLog( oSettings, 1, 'aTargets must be an array of targets, not a '+(typeof aTargets) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
328 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
329
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
330 for ( j=0, jLen=aTargets.length ; j<jLen ; j++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
331 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
332 if ( typeof aTargets[j] === 'number' && aTargets[j] >= 0 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
333 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
334 /* Add columns that we don't yet know about */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
335 while( oSettings.aoColumns.length <= aTargets[j] )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
336 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
337 _fnAddColumn( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
338 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
339
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
340 /* Integer, basic index */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
341 fn( aTargets[j], aoColDefs[i] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
342 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
343 else if ( typeof aTargets[j] === 'number' && aTargets[j] < 0 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
344 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
345 /* Negative integer, right to left column counting */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
346 fn( oSettings.aoColumns.length+aTargets[j], aoColDefs[i] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
347 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
348 else if ( typeof aTargets[j] === 'string' )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
349 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
350 /* Class name matching on TH element */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
351 for ( k=0, kLen=oSettings.aoColumns.length ; k<kLen ; k++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
352 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
353 if ( aTargets[j] == "_all" ||
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
354 $(oSettings.aoColumns[k].nTh).hasClass( aTargets[j] ) )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
355 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
356 fn( k, aoColDefs[i] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
357 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
358 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
359 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
360 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
361 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
362 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
363
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
364 // Statically defined columns array
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
365 if ( aoCols )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
366 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
367 for ( i=0, iLen=aoCols.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
368 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
369 fn( i, aoCols[i] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
370 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
371 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
372 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
373