annotate DataTables-1.9.4/media/src/core/core.data.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 * Add a data array to the table, creating DOM node etc. This is the parallel to
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
3 * _fnGatherData, but for adding rows from a Javascript source, rather than a
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
4 * DOM source.
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 {array} aData data array to be added
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
7 * @returns {int} >=0 if successful (index of new aoData entry), -1 if failed
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
8 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
9 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
10 function _fnAddData ( oSettings, aDataSupplied )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
11 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
12 var oCol;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
13
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
14 /* Take an independent copy of the data source so we can bash it about as we wish */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
15 var aDataIn = ($.isArray(aDataSupplied)) ?
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
16 aDataSupplied.slice() :
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
17 $.extend( true, {}, aDataSupplied );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
18
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
19 /* Create the object for storing information about this new row */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
20 var iRow = oSettings.aoData.length;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
21 var oData = $.extend( true, {}, DataTable.models.oRow );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
22 oData._aData = aDataIn;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
23 oSettings.aoData.push( oData );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
24
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
25 /* Create the cells */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
26 var nTd, sThisType;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
27 for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
28 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
29 oCol = oSettings.aoColumns[i];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
30
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
31 /* Use rendered data for filtering / sorting */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
32 if ( typeof oCol.fnRender === 'function' && oCol.bUseRendered && oCol.mData !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
33 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
34 _fnSetCellData( oSettings, iRow, i, _fnRender(oSettings, iRow, i) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
35 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
36 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
37 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
38 _fnSetCellData( oSettings, iRow, i, _fnGetCellData( oSettings, iRow, i ) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
39 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
40
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
41 /* See if we should auto-detect the column type */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
42 if ( oCol._bAutoType && oCol.sType != 'string' )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
43 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
44 /* Attempt to auto detect the type - same as _fnGatherData() */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
45 var sVarType = _fnGetCellData( oSettings, iRow, i, 'type' );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
46 if ( sVarType !== null && sVarType !== '' )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
47 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
48 sThisType = _fnDetectType( sVarType );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
49 if ( oCol.sType === null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
50 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
51 oCol.sType = sThisType;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
52 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
53 else if ( oCol.sType != sThisType && oCol.sType != "html" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
54 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
55 /* String is always the 'fallback' option */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
56 oCol.sType = 'string';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
57 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
58 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
59 }
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 /* Add to the display array */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
63 oSettings.aiDisplayMaster.push( iRow );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
64
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
65 /* Create the DOM information */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
66 if ( !oSettings.oFeatures.bDeferRender )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
67 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
68 _fnCreateTr( oSettings, iRow );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
69 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
70
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
71 return iRow;
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
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
75 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
76 * Read in the data from the target table from the DOM
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
77 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
78 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
79 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
80 function _fnGatherData( oSettings )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
81 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
82 var iLoop, i, iLen, j, jLen, jInner,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
83 nTds, nTrs, nTd, nTr, aLocalData, iThisIndex,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
84 iRow, iRows, iColumn, iColumns, sNodeName,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
85 oCol, oData;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
86
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
87 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
88 * Process by row first
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
89 * Add the data object for the whole table - storing the tr node. Note - no point in getting
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
90 * DOM based data if we are going to go and replace it with Ajax source data.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
91 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
92 if ( oSettings.bDeferLoading || oSettings.sAjaxSource === null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
93 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
94 nTr = oSettings.nTBody.firstChild;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
95 while ( nTr )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
96 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
97 if ( nTr.nodeName.toUpperCase() == "TR" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
98 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
99 iThisIndex = oSettings.aoData.length;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
100 nTr._DT_RowIndex = iThisIndex;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
101 oSettings.aoData.push( $.extend( true, {}, DataTable.models.oRow, {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
102 "nTr": nTr
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
103 } ) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
104
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
105 oSettings.aiDisplayMaster.push( iThisIndex );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
106 nTd = nTr.firstChild;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
107 jInner = 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
108 while ( nTd )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
109 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
110 sNodeName = nTd.nodeName.toUpperCase();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
111 if ( sNodeName == "TD" || sNodeName == "TH" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
112 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
113 _fnSetCellData( oSettings, iThisIndex, jInner, $.trim(nTd.innerHTML) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
114 jInner++;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
115 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
116 nTd = nTd.nextSibling;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
117 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
118 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
119 nTr = nTr.nextSibling;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
120 }
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 /* Gather in the TD elements of the Table - note that this is basically the same as
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
124 * fnGetTdNodes, but that function takes account of hidden columns, which we haven't yet
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
125 * setup!
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
126 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
127 nTrs = _fnGetTrNodes( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
128 nTds = [];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
129 for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
130 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
131 nTd = nTrs[i].firstChild;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
132 while ( nTd )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
133 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
134 sNodeName = nTd.nodeName.toUpperCase();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
135 if ( sNodeName == "TD" || sNodeName == "TH" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
136 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
137 nTds.push( nTd );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
138 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
139 nTd = nTd.nextSibling;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
140 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
141 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
142
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
143 /* Now process by column */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
144 for ( iColumn=0, iColumns=oSettings.aoColumns.length ; iColumn<iColumns ; iColumn++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
145 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
146 oCol = oSettings.aoColumns[iColumn];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
147
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
148 /* Get the title of the column - unless there is a user set one */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
149 if ( oCol.sTitle === null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
150 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
151 oCol.sTitle = oCol.nTh.innerHTML;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
152 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
153
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
154 var
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
155 bAutoType = oCol._bAutoType,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
156 bRender = typeof oCol.fnRender === 'function',
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
157 bClass = oCol.sClass !== null,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
158 bVisible = oCol.bVisible,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
159 nCell, sThisType, sRendered, sValType;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
160
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
161 /* A single loop to rule them all (and be more efficient) */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
162 if ( bAutoType || bRender || bClass || !bVisible )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
163 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
164 for ( iRow=0, iRows=oSettings.aoData.length ; iRow<iRows ; iRow++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
165 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
166 oData = oSettings.aoData[iRow];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
167 nCell = nTds[ (iRow*iColumns) + iColumn ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
168
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
169 /* Type detection */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
170 if ( bAutoType && oCol.sType != 'string' )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
171 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
172 sValType = _fnGetCellData( oSettings, iRow, iColumn, 'type' );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
173 if ( sValType !== '' )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
174 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
175 sThisType = _fnDetectType( sValType );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
176 if ( oCol.sType === null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
177 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
178 oCol.sType = sThisType;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
179 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
180 else if ( oCol.sType != sThisType &&
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
181 oCol.sType != "html" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
182 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
183 /* String is always the 'fallback' option */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
184 oCol.sType = 'string';
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 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
188
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
189 if ( oCol.mRender )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
190 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
191 // mRender has been defined, so we need to get the value and set it
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
192 nCell.innerHTML = _fnGetCellData( oSettings, iRow, iColumn, 'display' );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
193 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
194 else if ( oCol.mData !== iColumn )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
195 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
196 // If mData is not the same as the column number, then we need to
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
197 // get the dev set value. If it is the column, no point in wasting
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
198 // time setting the value that is already there!
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
199 nCell.innerHTML = _fnGetCellData( oSettings, iRow, iColumn, 'display' );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
200 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
201
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
202 /* Rendering */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
203 if ( bRender )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
204 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
205 sRendered = _fnRender( oSettings, iRow, iColumn );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
206 nCell.innerHTML = sRendered;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
207 if ( oCol.bUseRendered )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
208 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
209 /* Use the rendered data for filtering / sorting */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
210 _fnSetCellData( oSettings, iRow, iColumn, sRendered );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
211 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
212 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
213
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
214 /* Classes */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
215 if ( bClass )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
216 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
217 nCell.className += ' '+oCol.sClass;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
218 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
219
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
220 /* Column visibility */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
221 if ( !bVisible )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
222 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
223 oData._anHidden[iColumn] = nCell;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
224 nCell.parentNode.removeChild( nCell );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
225 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
226 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
227 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
228 oData._anHidden[iColumn] = null;
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 if ( oCol.fnCreatedCell )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
232 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
233 oCol.fnCreatedCell.call( oSettings.oInstance,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
234 nCell, _fnGetCellData( oSettings, iRow, iColumn, 'display' ), oData._aData, iRow, iColumn
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
235 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
236 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
237 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
238 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
239 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
240
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
241 /* Row created callbacks */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
242 if ( oSettings.aoRowCreatedCallback.length !== 0 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
243 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
244 for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
245 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
246 oData = oSettings.aoData[i];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
247 _fnCallbackFire( oSettings, 'aoRowCreatedCallback', null, [oData.nTr, oData._aData, i] );
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 }
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 * Take a TR element and convert it to an index in aoData
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
255 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
256 * @param {node} n the TR element to find
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
257 * @returns {int} index if the node is found, null if not
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 _fnNodeToDataIndex( oSettings, n )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
261 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
262 return (n._DT_RowIndex!==undefined) ? n._DT_RowIndex : null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
263 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
264
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
265
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
266 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
267 * Take a TD element and convert it into a column data index (not the visible index)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
268 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
269 * @param {int} iRow The row number the TD/TH can be found in
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
270 * @param {node} n The TD/TH element to find
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
271 * @returns {int} index if the node is found, -1 if not
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
272 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
273 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
274 function _fnNodeToColumnIndex( oSettings, iRow, n )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
275 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
276 var anCells = _fnGetTdNodes( oSettings, iRow );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
277
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
278 for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
279 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
280 if ( anCells[i] === n )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
281 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
282 return i;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
283 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
284 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
285 return -1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
286 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
287
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
288
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
289 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
290 * Get an array of data for a given row from the internal data cache
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
291 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
292 * @param {int} iRow aoData row id
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
293 * @param {string} sSpecific data get type ('type' 'filter' 'sort')
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
294 * @param {array} aiColumns Array of column indexes to get data from
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
295 * @returns {array} Data array
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
296 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
297 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
298 function _fnGetRowData( oSettings, iRow, sSpecific, aiColumns )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
299 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
300 var out = [];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
301 for ( var i=0, iLen=aiColumns.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
302 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
303 out.push( _fnGetCellData( oSettings, iRow, aiColumns[i], sSpecific ) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
304 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
305 return out;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
306 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
307
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
308
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
309 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
310 * Get the data for a given cell from the internal cache, taking into account data mapping
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
311 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
312 * @param {int} iRow aoData row id
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
313 * @param {int} iCol Column index
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
314 * @param {string} sSpecific data get type ('display', 'type' 'filter' 'sort')
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
315 * @returns {*} Cell data
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
316 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
317 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
318 function _fnGetCellData( oSettings, iRow, iCol, sSpecific )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
319 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
320 var sData;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
321 var oCol = oSettings.aoColumns[iCol];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
322 var oData = oSettings.aoData[iRow]._aData;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
323
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
324 if ( (sData=oCol.fnGetData( oData, sSpecific )) === undefined )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
325 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
326 if ( oSettings.iDrawError != oSettings.iDraw && oCol.sDefaultContent === null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
327 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
328 _fnLog( oSettings, 0, "Requested unknown parameter "+
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
329 (typeof oCol.mData=='function' ? '{mData function}' : "'"+oCol.mData+"'")+
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
330 " from the data source for row "+iRow );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
331 oSettings.iDrawError = oSettings.iDraw;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
332 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
333 return oCol.sDefaultContent;
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 /* When the data source is null, we can use default column data */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
337 if ( sData === null && oCol.sDefaultContent !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
338 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
339 sData = oCol.sDefaultContent;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
340 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
341 else if ( typeof sData === 'function' )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
342 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
343 /* If the data source is a function, then we run it and use the return */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
344 return sData();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
345 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
346
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
347 if ( sSpecific == 'display' && sData === null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
348 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
349 return '';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
350 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
351 return sData;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
352 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
353
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
354
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
355 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
356 * Set the value for a specific cell, into the internal data cache
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
357 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
358 * @param {int} iRow aoData row id
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
359 * @param {int} iCol Column index
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
360 * @param {*} val Value to set
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
361 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
362 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
363 function _fnSetCellData( oSettings, iRow, iCol, val )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
364 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
365 var oCol = oSettings.aoColumns[iCol];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
366 var oData = oSettings.aoData[iRow]._aData;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
367
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
368 oCol.fnSetData( oData, val );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
369 }
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 // Private variable that is used to match array syntax in the data property object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
373 var __reArray = /\[.*?\]$/;
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 * Return a function that can be used to get data from a source object, taking
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
377 * into account the ability to use nested objects as a source
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
378 * @param {string|int|function} mSource The data source for the object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
379 * @returns {function} Data get function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
380 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
381 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
382 function _fnGetObjectDataFn( mSource )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
383 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
384 if ( mSource === null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
385 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
386 /* Give an empty string for rendering / sorting etc */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
387 return function (data, type) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
388 return null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
389 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
390 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
391 else if ( typeof mSource === 'function' )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
392 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
393 return function (data, type, extra) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
394 return mSource( data, type, extra );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
395 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
396 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
397 else if ( typeof mSource === 'string' && (mSource.indexOf('.') !== -1 || mSource.indexOf('[') !== -1) )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
398 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
399 /* If there is a . in the source string then the data source is in a
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
400 * nested object so we loop over the data for each level to get the next
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
401 * level down. On each loop we test for undefined, and if found immediately
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
402 * return. This allows entire objects to be missing and sDefaultContent to
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
403 * be used if defined, rather than throwing an error
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
404 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
405 var fetchData = function (data, type, src) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
406 var a = src.split('.');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
407 var arrayNotation, out, innerSrc;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
408
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
409 if ( src !== "" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
410 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
411 for ( var i=0, iLen=a.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
412 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
413 // Check if we are dealing with an array notation request
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
414 arrayNotation = a[i].match(__reArray);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
415
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
416 if ( arrayNotation ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
417 a[i] = a[i].replace(__reArray, '');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
418
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
419 // Condition allows simply [] to be passed in
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
420 if ( a[i] !== "" ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
421 data = data[ a[i] ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
422 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
423 out = [];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
424
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
425 // Get the remainder of the nested object to get
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
426 a.splice( 0, i+1 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
427 innerSrc = a.join('.');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
428
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
429 // Traverse each entry in the array getting the properties requested
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
430 for ( var j=0, jLen=data.length ; j<jLen ; j++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
431 out.push( fetchData( data[j], type, innerSrc ) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
432 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
433
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
434 // If a string is given in between the array notation indicators, that
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
435 // is used to join the strings together, otherwise an array is returned
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
436 var join = arrayNotation[0].substring(1, arrayNotation[0].length-1);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
437 data = (join==="") ? out : out.join(join);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
438
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
439 // The inner call to fetchData has already traversed through the remainder
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
440 // of the source requested, so we exit from the loop
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
441 break;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
442 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
443
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
444 if ( data === null || data[ a[i] ] === undefined )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
445 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
446 return undefined;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
447 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
448 data = data[ a[i] ];
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
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
452 return data;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
453 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
454
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
455 return function (data, type) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
456 return fetchData( data, type, mSource );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
457 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
458 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
459 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
460 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
461 /* Array or flat object mapping */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
462 return function (data, type) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
463 return data[mSource];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
464 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
465 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
466 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
467
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
468
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
469 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
470 * Return a function that can be used to set data from a source object, taking
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
471 * into account the ability to use nested objects as a source
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
472 * @param {string|int|function} mSource The data source for the object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
473 * @returns {function} Data set function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
474 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
475 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
476 function _fnSetObjectDataFn( mSource )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
477 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
478 if ( mSource === null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
479 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
480 /* Nothing to do when the data source is null */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
481 return function (data, val) {};
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
482 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
483 else if ( typeof mSource === 'function' )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
484 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
485 return function (data, val) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
486 mSource( data, 'set', val );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
487 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
488 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
489 else if ( typeof mSource === 'string' && (mSource.indexOf('.') !== -1 || mSource.indexOf('[') !== -1) )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
490 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
491 /* Like the get, we need to get data from a nested object */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
492 var setData = function (data, val, src) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
493 var a = src.split('.'), b;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
494 var arrayNotation, o, innerSrc;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
495
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
496 for ( var i=0, iLen=a.length-1 ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
497 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
498 // Check if we are dealing with an array notation request
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
499 arrayNotation = a[i].match(__reArray);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
500
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
501 if ( arrayNotation )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
502 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
503 a[i] = a[i].replace(__reArray, '');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
504 data[ a[i] ] = [];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
505
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
506 // Get the remainder of the nested object to set so we can recurse
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
507 b = a.slice();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
508 b.splice( 0, i+1 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
509 innerSrc = b.join('.');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
510
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
511 // Traverse each entry in the array setting the properties requested
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
512 for ( var j=0, jLen=val.length ; j<jLen ; j++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
513 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
514 o = {};
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
515 setData( o, val[j], innerSrc );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
516 data[ a[i] ].push( o );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
517 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
518
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
519 // The inner call to setData has already traversed through the remainder
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
520 // of the source and has set the data, thus we can exit here
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
521 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
522 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
523
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
524 // If the nested object doesn't currently exist - since we are
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
525 // trying to set the value - create it
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
526 if ( data[ a[i] ] === null || data[ a[i] ] === undefined )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
527 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
528 data[ a[i] ] = {};
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
529 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
530 data = data[ a[i] ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
531 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
532
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
533 // If array notation is used, we just want to strip it and use the property name
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
534 // and assign the value. If it isn't used, then we get the result we want anyway
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
535 data[ a[a.length-1].replace(__reArray, '') ] = val;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
536 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
537
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
538 return function (data, val) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
539 return setData( data, val, mSource );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
540 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
541 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
542 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
543 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
544 /* Array or flat object mapping */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
545 return function (data, val) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
546 data[mSource] = val;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
547 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
548 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
549 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
550
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
551
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
552 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
553 * Return an array with the full table data
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
554 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
555 * @returns array {array} aData Master data array
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
556 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
557 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
558 function _fnGetDataMaster ( oSettings )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
559 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
560 var aData = [];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
561 var iLen = oSettings.aoData.length;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
562 for ( var i=0 ; i<iLen; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
563 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
564 aData.push( oSettings.aoData[i]._aData );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
565 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
566 return aData;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
567 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
568
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
569
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
570 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
571 * Nuke the table
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
572 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
573 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
574 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
575 function _fnClearTable( oSettings )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
576 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
577 oSettings.aoData.splice( 0, oSettings.aoData.length );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
578 oSettings.aiDisplayMaster.splice( 0, oSettings.aiDisplayMaster.length );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
579 oSettings.aiDisplay.splice( 0, oSettings.aiDisplay.length );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
580 _fnCalculateEnd( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
581 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
582
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
583
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
584 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
585 * Take an array of integers (index array) and remove a target integer (value - not
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
586 * the key!)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
587 * @param {array} a Index array to target
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
588 * @param {int} iTarget value to find
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
589 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
590 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
591 function _fnDeleteIndex( a, iTarget )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
592 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
593 var iTargetIndex = -1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
594
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
595 for ( var i=0, iLen=a.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
596 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
597 if ( a[i] == iTarget )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
598 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
599 iTargetIndex = i;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
600 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
601 else if ( a[i] > iTarget )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
602 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
603 a[i]--;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
604 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
605 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
606
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
607 if ( iTargetIndex != -1 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
608 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
609 a.splice( iTargetIndex, 1 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
610 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
611 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
612
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
613
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
614 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
615 * Call the developer defined fnRender function for a given cell (row/column) with
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
616 * the required parameters and return the result.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
617 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
618 * @param {int} iRow aoData index for the row
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
619 * @param {int} iCol aoColumns index for the column
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
620 * @returns {*} Return of the developer's fnRender function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
621 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
622 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
623 function _fnRender( oSettings, iRow, iCol )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
624 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
625 var oCol = oSettings.aoColumns[iCol];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
626
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
627 return oCol.fnRender( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
628 "iDataRow": iRow,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
629 "iDataColumn": iCol,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
630 "oSettings": oSettings,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
631 "aData": oSettings.aoData[iRow]._aData,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
632 "mDataProp": oCol.mData
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
633 }, _fnGetCellData(oSettings, iRow, iCol, 'display') );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
634 }