3 * Return the settings object for a particular table
4 * @param {node} nTable table we are using as a dataTable
5 * @returns {object} Settings object - or null if not found
6 * @memberof DataTable#oApi
8 function _fnSettingsFromNode ( nTable )
10 for ( var i=0 ; i<DataTable.settings.length ; i++ )
12 if ( DataTable.settings[i].nTable === nTable )
14 return DataTable.settings[i];
23 * Return an array with the TR nodes for the table
24 * @param {object} oSettings dataTables settings object
25 * @returns {array} TR array
26 * @memberof DataTable#oApi
28 function _fnGetTrNodes ( oSettings )
31 var aoData = oSettings.aoData;
32 for ( var i=0, iLen=aoData.length ; i<iLen ; i++ )
34 if ( aoData[i].nTr !== null )
36 aNodes.push( aoData[i].nTr );
44 * Return an flat array with all TD nodes for the table, or row
45 * @param {object} oSettings dataTables settings object
46 * @param {int} [iIndividualRow] aoData index to get the nodes for - optional
47 * if not given then the return array will contain all nodes for the table
48 * @returns {array} TD array
49 * @memberof DataTable#oApi
51 function _fnGetTdNodes ( oSettings, iIndividualRow )
56 var iRow, iRows=oSettings.aoData.length,
57 iColumn, iColumns, oData, sNodeName, iStart=0, iEnd=iRows;
59 /* Allow the collection to be limited to just one row */
60 if ( iIndividualRow !== undefined )
62 iStart = iIndividualRow;
63 iEnd = iIndividualRow+1;
66 for ( iRow=iStart ; iRow<iEnd ; iRow++ )
68 oData = oSettings.aoData[iRow];
69 if ( oData.nTr !== null )
71 /* get the TD child nodes - taking into account text etc nodes */
73 nTd = oData.nTr.firstChild;
76 sNodeName = nTd.nodeName.toLowerCase();
77 if ( sNodeName == 'td' || sNodeName == 'th' )
81 nTd = nTd.nextSibling;
85 for ( iColumn=0, iColumns=oSettings.aoColumns.length ; iColumn<iColumns ; iColumn++ )
87 if ( oSettings.aoColumns[iColumn].bVisible )
89 anReturn.push( anTds[iColumn-iCorrector] );
93 anReturn.push( oData._anHidden[iColumn] );
105 * Log an error message
106 * @param {object} oSettings dataTables settings object
107 * @param {int} iLevel log error messages, or display them to the user
108 * @param {string} sMesg error message
109 * @memberof DataTable#oApi
111 function _fnLog( oSettings, iLevel, sMesg )
113 var sAlert = (oSettings===null) ?
114 "DataTables warning: "+sMesg :
115 "DataTables warning (table id = '"+oSettings.sTableId+"'): "+sMesg;
119 if ( DataTable.ext.sErrMode == 'alert' )
125 throw new Error(sAlert);
129 else if ( window.console && console.log )
131 console.log( sAlert );
137 * See if a property is defined on one object, if so assign it to the other object
138 * @param {object} oRet target object
139 * @param {object} oSrc source object
140 * @param {string} sName property
141 * @param {string} [sMappedName] name to map too - optional, sName used if not given
142 * @memberof DataTable#oApi
144 function _fnMap( oRet, oSrc, sName, sMappedName )
146 if ( sMappedName === undefined )
150 if ( oSrc[sName] !== undefined )
152 oRet[sMappedName] = oSrc[sName];
158 * Extend objects - very similar to jQuery.extend, but deep copy objects, and shallow
159 * copy arrays. The reason we need to do this, is that we don't want to deep copy array
160 * init values (such as aaSorting) since the dev wouldn't be able to override them, but
161 * we do want to deep copy arrays.
162 * @param {object} oOut Object to extend
163 * @param {object} oExtender Object from which the properties will be applied to oOut
164 * @returns {object} oOut Reference, just for convenience - oOut === the return.
165 * @memberof DataTable#oApi
166 * @todo This doesn't take account of arrays inside the deep copied objects.
168 function _fnExtend( oOut, oExtender )
172 for ( var prop in oExtender )
174 if ( oExtender.hasOwnProperty(prop) )
176 val = oExtender[prop];
178 if ( typeof oInit[prop] === 'object' && val !== null && $.isArray(val) === false )
180 $.extend( true, oOut[prop], val );
194 * Bind an event handers to allow a click or return key to activate the callback.
195 * This is good for accessibility since a return on the keyboard will have the
196 * same effect as a click, if the element has focus.
197 * @param {element} n Element to bind the action to
198 * @param {object} oData Data object to pass to the triggered function
199 * @param {function} fn Callback function for when the event is triggered
200 * @memberof DataTable#oApi
202 function _fnBindAction( n, oData, fn )
205 .bind( 'click.DT', oData, function (e) {
206 n.blur(); // Remove focus outline for mouse users
209 .bind( 'keypress.DT', oData, function (e){
210 if ( e.which === 13 ) {
213 .bind( 'selectstart.DT', function () {
214 /* Take the brutal approach to cancelling text selection */
221 * Register a callback function. Easily allows a callback function to be added to
222 * an array store of callback functions that can then all be called together.
223 * @param {object} oSettings dataTables settings object
224 * @param {string} sStore Name of the array storage for the callbacks in oSettings
225 * @param {function} fn Function to be called back
226 * @param {string} sName Identifying name for the callback (i.e. a label)
227 * @memberof DataTable#oApi
229 function _fnCallbackReg( oSettings, sStore, fn, sName )
233 oSettings[sStore].push( {
242 * Fire callback functions and trigger events. Note that the loop over the callback
243 * array store is done backwards! Further note that you do not want to fire off triggers
244 * in time sensitive applications (for example cell creation) as its slow.
245 * @param {object} oSettings dataTables settings object
246 * @param {string} sStore Name of the array storage for the callbacks in oSettings
247 * @param {string} sTrigger Name of the jQuery custom event to trigger. If null no trigger
249 * @param {array} aArgs Array of arguments to pass to the callback function / trigger
250 * @memberof DataTable#oApi
252 function _fnCallbackFire( oSettings, sStore, sTrigger, aArgs )
254 var aoStore = oSettings[sStore];
257 for ( var i=aoStore.length-1 ; i>=0 ; i-- )
259 aRet.push( aoStore[i].fn.apply( oSettings.oInstance, aArgs ) );
262 if ( sTrigger !== null )
264 $(oSettings.oInstance).trigger(sTrigger, aArgs);
272 * JSON stringify. If JSON.stringify it provided by the browser, json2.js or any other
273 * library, then we use that as it is fast, safe and accurate. If the function isn't
274 * available then we need to built it ourselves - the inspiration for this function comes
275 * from Craig Buckler ( http://www.sitepoint.com/javascript-json-serialization/ ). It is
276 * not perfect and absolutely should not be used as a replacement to json2.js - but it does
277 * do what we need, without requiring a dependency for DataTables.
278 * @param {object} o JSON object to be converted
279 * @returns {string} JSON string
280 * @memberof DataTable#oApi
282 var _fnJsonString = (window.JSON) ? JSON.stringify : function( o )
284 /* Not an object or array */
285 var sType = typeof o;
286 if (sType !== "object" || o === null)
289 if (sType === "string")
296 /* If object or array, need to recurse over it */
305 sType = typeof mValue;
307 if (sType === "string")
309 mValue = '"'+mValue+'"';
311 else if (sType === "object" && mValue !== null)
313 mValue = _fnJsonString(mValue);
316 json.push((bArr ? "" : '"'+sProp+'":') + mValue);
319 return (bArr ? "[" : "{") + json + (bArr ? "]" : "}");
324 * From some browsers (specifically IE6/7) we need special handling to work around browser
325 * bugs - this function is used to detect when these workarounds are needed.
326 * @param {object} oSettings dataTables settings object
327 * @memberof DataTable#oApi
329 function _fnBrowserDetect( oSettings )
331 /* IE6/7 will oversize a width 100% element inside a scrolling element, to include the
332 * width of the scrollbar, while other browsers ensure the inner element is contained
333 * without forcing scrolling
336 '<div style="position:absolute; top:0; left:0; height:1px; width:1px; overflow:hidden">'+
337 '<div style="position:absolute; top:1px; left:1px; width:100px; overflow:scroll;">'+
338 '<div id="DT_BrowserTest" style="width:100%; height:10px;"></div>'+
342 document.body.appendChild( n );
343 oSettings.oBrowser.bScrollOversize = $('#DT_BrowserTest', n)[0].offsetWidth === 100 ? true : false;
344 document.body.removeChild( n );