annotate DataTables-1.9.4/media/src/api/api.methods.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 * Perform a jQuery selector action on the table's TR elements (from the tbody) and
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
3 * return the resulting jQuery object.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
4 * @param {string|node|jQuery} sSelector jQuery selector or node collection to act on
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
5 * @param {object} [oOpts] Optional parameters for modifying the rows to be included
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
6 * @param {string} [oOpts.filter=none] Select TR elements that meet the current filter
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
7 * criterion ("applied") or all TR elements (i.e. no filter).
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
8 * @param {string} [oOpts.order=current] Order of the TR elements in the processed array.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
9 * Can be either 'current', whereby the current sorting of the table is used, or
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
10 * 'original' whereby the original order the data was read into the table is used.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
11 * @param {string} [oOpts.page=all] Limit the selection to the currently displayed page
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
12 * ("current") or not ("all"). If 'current' is given, then order is assumed to be
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
13 * 'current' and filter is 'applied', regardless of what they might be given as.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
14 * @returns {object} jQuery object, filtered by the given selector.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
15 * @dtopt API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
16 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
17 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
18 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
19 * var oTable = $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
20 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
21 * // Highlight every second row
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
22 * oTable.$('tr:odd').css('backgroundColor', 'blue');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
23 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
24 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
25 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
26 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
27 * var oTable = $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
28 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
29 * // Filter to rows with 'Webkit' in them, add a background colour and then
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
30 * // remove the filter, thus highlighting the 'Webkit' rows only.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
31 * oTable.fnFilter('Webkit');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
32 * oTable.$('tr', {"filter": "applied"}).css('backgroundColor', 'blue');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
33 * oTable.fnFilter('');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
34 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
35 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
36 this.$ = function ( sSelector, oOpts )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
37 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
38 var i, iLen, a = [], tr;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
39 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
40 var aoData = oSettings.aoData;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
41 var aiDisplay = oSettings.aiDisplay;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
42 var aiDisplayMaster = oSettings.aiDisplayMaster;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
43
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
44 if ( !oOpts )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
45 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
46 oOpts = {};
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 oOpts = $.extend( {}, {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
50 "filter": "none", // applied
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
51 "order": "current", // "original"
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
52 "page": "all" // current
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
53 }, oOpts );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
54
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
55 // Current page implies that order=current and fitler=applied, since it is fairly
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
56 // senseless otherwise
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
57 if ( oOpts.page == 'current' )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
58 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
59 for ( i=oSettings._iDisplayStart, iLen=oSettings.fnDisplayEnd() ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
60 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
61 tr = aoData[ aiDisplay[i] ].nTr;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
62 if ( tr )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
63 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
64 a.push( tr );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
65 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
66 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
67 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
68 else if ( oOpts.order == "current" && oOpts.filter == "none" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
69 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
70 for ( i=0, iLen=aiDisplayMaster.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
71 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
72 tr = aoData[ aiDisplayMaster[i] ].nTr;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
73 if ( tr )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
74 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
75 a.push( tr );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
76 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
77 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
78 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
79 else if ( oOpts.order == "current" && oOpts.filter == "applied" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
80 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
81 for ( i=0, iLen=aiDisplay.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
82 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
83 tr = aoData[ aiDisplay[i] ].nTr;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
84 if ( tr )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
85 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
86 a.push( tr );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
87 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
88 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
89 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
90 else if ( oOpts.order == "original" && oOpts.filter == "none" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
91 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
92 for ( i=0, iLen=aoData.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
93 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
94 tr = aoData[ i ].nTr ;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
95 if ( tr )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
96 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
97 a.push( tr );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
98 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
99 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
100 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
101 else if ( oOpts.order == "original" && oOpts.filter == "applied" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
102 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
103 for ( i=0, iLen=aoData.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
104 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
105 tr = aoData[ i ].nTr;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
106 if ( $.inArray( i, aiDisplay ) !== -1 && tr )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
107 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
108 a.push( tr );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
109 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
110 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
111 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
112 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
113 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
114 _fnLog( oSettings, 1, "Unknown selection options" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
115 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
116
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
117 /* We need to filter on the TR elements and also 'find' in their descendants
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
118 * to make the selector act like it would in a full table - so we need
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
119 * to build both results and then combine them together
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
120 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
121 var jqA = $(a);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
122 var jqTRs = jqA.filter( sSelector );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
123 var jqDescendants = jqA.find( sSelector );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
124
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
125 return $( [].concat($.makeArray(jqTRs), $.makeArray(jqDescendants)) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
126 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
127
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
128
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
129 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
130 * Almost identical to $ in operation, but in this case returns the data for the matched
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
131 * rows - as such, the jQuery selector used should match TR row nodes or TD/TH cell nodes
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
132 * rather than any descendants, so the data can be obtained for the row/cell. If matching
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
133 * rows are found, the data returned is the original data array/object that was used to
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
134 * create the row (or a generated array if from a DOM source).
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
135 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
136 * This method is often useful in-combination with $ where both functions are given the
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
137 * same parameters and the array indexes will match identically.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
138 * @param {string|node|jQuery} sSelector jQuery selector or node collection to act on
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
139 * @param {object} [oOpts] Optional parameters for modifying the rows to be included
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
140 * @param {string} [oOpts.filter=none] Select elements that meet the current filter
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
141 * criterion ("applied") or all elements (i.e. no filter).
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
142 * @param {string} [oOpts.order=current] Order of the data in the processed array.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
143 * Can be either 'current', whereby the current sorting of the table is used, or
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
144 * 'original' whereby the original order the data was read into the table is used.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
145 * @param {string} [oOpts.page=all] Limit the selection to the currently displayed page
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
146 * ("current") or not ("all"). If 'current' is given, then order is assumed to be
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
147 * 'current' and filter is 'applied', regardless of what they might be given as.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
148 * @returns {array} Data for the matched elements. If any elements, as a result of the
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
149 * selector, were not TR, TD or TH elements in the DataTable, they will have a null
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
150 * entry in the array.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
151 * @dtopt API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
152 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
153 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
154 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
155 * var oTable = $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
156 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
157 * // Get the data from the first row in the table
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
158 * var data = oTable._('tr:first');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
159 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
160 * // Do something useful with the data
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
161 * alert( "First cell is: "+data[0] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
162 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
163 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
164 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
165 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
166 * var oTable = $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
167 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
168 * // Filter to 'Webkit' and get all data for
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
169 * oTable.fnFilter('Webkit');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
170 * var data = oTable._('tr', {"filter": "applied"});
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
171 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
172 * // Do something with the data
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
173 * alert( data.length+" rows matched the filter" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
174 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
175 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
176 this._ = function ( sSelector, oOpts )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
177 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
178 var aOut = [];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
179 var i, iLen, iIndex;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
180 var aTrs = this.$( sSelector, oOpts );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
181
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
182 for ( i=0, iLen=aTrs.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
183 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
184 aOut.push( this.fnGetData(aTrs[i]) );
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 return aOut;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
188 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
189
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
190
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
191 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
192 * Add a single new row or multiple rows of data to the table. Please note
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
193 * that this is suitable for client-side processing only - if you are using
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
194 * server-side processing (i.e. "bServerSide": true), then to add data, you
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
195 * must add it to the data source, i.e. the server-side, through an Ajax call.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
196 * @param {array|object} mData The data to be added to the table. This can be:
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
197 * <ul>
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
198 * <li>1D array of data - add a single row with the data provided</li>
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
199 * <li>2D array of arrays - add multiple rows in a single call</li>
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
200 * <li>object - data object when using <i>mData</i></li>
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
201 * <li>array of objects - multiple data objects when using <i>mData</i></li>
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
202 * </ul>
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
203 * @param {bool} [bRedraw=true] redraw the table or not
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
204 * @returns {array} An array of integers, representing the list of indexes in
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
205 * <i>aoData</i> ({@link DataTable.models.oSettings}) that have been added to
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
206 * the table.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
207 * @dtopt API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
208 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
209 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
210 * // Global var for counter
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
211 * var giCount = 2;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
212 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
213 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
214 * $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
215 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
216 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
217 * function fnClickAddRow() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
218 * $('#example').dataTable().fnAddData( [
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
219 * giCount+".1",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
220 * giCount+".2",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
221 * giCount+".3",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
222 * giCount+".4" ]
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 * giCount++;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
226 * }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
227 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
228 this.fnAddData = function( mData, bRedraw )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
229 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
230 if ( mData.length === 0 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
231 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
232 return [];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
233 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
234
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
235 var aiReturn = [];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
236 var iTest;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
237
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
238 /* Find settings from table node */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
239 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
240
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
241 /* Check if we want to add multiple rows or not */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
242 if ( typeof mData[0] === "object" && mData[0] !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
243 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
244 for ( var i=0 ; i<mData.length ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
245 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
246 iTest = _fnAddData( oSettings, mData[i] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
247 if ( iTest == -1 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
248 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
249 return aiReturn;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
250 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
251 aiReturn.push( iTest );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
252 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
253 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
254 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
255 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
256 iTest = _fnAddData( oSettings, mData );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
257 if ( iTest == -1 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
258 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
259 return aiReturn;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
260 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
261 aiReturn.push( iTest );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
262 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
263
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
264 oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
265
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
266 if ( bRedraw === undefined || bRedraw )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
267 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
268 _fnReDraw( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
269 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
270 return aiReturn;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
271 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
272
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 * This function will make DataTables recalculate the column sizes, based on the data
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
276 * contained in the table and the sizes applied to the columns (in the DOM, CSS or
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
277 * through the sWidth parameter). This can be useful when the width of the table's
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
278 * parent element changes (for example a window resize).
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
279 * @param {boolean} [bRedraw=true] Redraw the table or not, you will typically want to
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
280 * @dtopt API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
281 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
282 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
283 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
284 * var oTable = $('#example').dataTable( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
285 * "sScrollY": "200px",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
286 * "bPaginate": false
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 * $(window).bind('resize', function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
290 * oTable.fnAdjustColumnSizing();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
291 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
292 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
293 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
294 this.fnAdjustColumnSizing = function ( bRedraw )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
295 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
296 var oSettings = _fnSettingsFromNode(this[DataTable.ext.iApiIndex]);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
297 _fnAdjustColumnSizing( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
298
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
299 if ( bRedraw === undefined || bRedraw )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
300 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
301 this.fnDraw( false );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
302 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
303 else if ( oSettings.oScroll.sX !== "" || oSettings.oScroll.sY !== "" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
304 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
305 /* If not redrawing, but scrolling, we want to apply the new column sizes anyway */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
306 this.oApi._fnScrollDraw(oSettings);
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
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
311 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
312 * Quickly and simply clear a table
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
313 * @param {bool} [bRedraw=true] redraw the table or not
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
314 * @dtopt API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
315 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
316 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
317 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
318 * var oTable = $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
319 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
320 * // Immediately 'nuke' the current rows (perhaps waiting for an Ajax callback...)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
321 * oTable.fnClearTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
322 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
323 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
324 this.fnClearTable = function( bRedraw )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
325 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
326 /* Find settings from table node */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
327 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
328 _fnClearTable( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
329
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
330 if ( bRedraw === undefined || bRedraw )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
331 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
332 _fnDraw( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
333 }
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
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
337 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
338 * The exact opposite of 'opening' a row, this function will close any rows which
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
339 * are currently 'open'.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
340 * @param {node} nTr the table row to 'close'
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
341 * @returns {int} 0 on success, or 1 if failed (can't find the row)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
342 * @dtopt API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
343 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
344 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
345 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
346 * var oTable;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
347 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
348 * // 'open' an information row when a row is clicked on
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
349 * $('#example tbody tr').click( function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
350 * if ( oTable.fnIsOpen(this) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
351 * oTable.fnClose( this );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
352 * } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
353 * oTable.fnOpen( this, "Temporary row opened", "info_row" );
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 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
357 * oTable = $('#example').dataTable();
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 this.fnClose = function( nTr )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
361 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
362 /* Find settings from table node */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
363 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
364
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
365 for ( var i=0 ; i<oSettings.aoOpenRows.length ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
366 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
367 if ( oSettings.aoOpenRows[i].nParent == nTr )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
368 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
369 var nTrParent = oSettings.aoOpenRows[i].nTr.parentNode;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
370 if ( nTrParent )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
371 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
372 /* Remove it if it is currently on display */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
373 nTrParent.removeChild( oSettings.aoOpenRows[i].nTr );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
374 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
375 oSettings.aoOpenRows.splice( i, 1 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
376 return 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
377 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
378 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
379 return 1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
380 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
381
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
382
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
383 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
384 * Remove a row for the table
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
385 * @param {mixed} mTarget The index of the row from aoData to be deleted, or
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
386 * the TR element you want to delete
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
387 * @param {function|null} [fnCallBack] Callback function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
388 * @param {bool} [bRedraw=true] Redraw the table or not
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
389 * @returns {array} The row that was deleted
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
390 * @dtopt API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
391 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
392 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
393 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
394 * var oTable = $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
395 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
396 * // Immediately remove the first row
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
397 * oTable.fnDeleteRow( 0 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
398 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
399 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
400 this.fnDeleteRow = function( mTarget, fnCallBack, bRedraw )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
401 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
402 /* Find settings from table node */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
403 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
404 var i, iLen, iAODataIndex;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
405
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
406 iAODataIndex = (typeof mTarget === 'object') ?
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
407 _fnNodeToDataIndex(oSettings, mTarget) : mTarget;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
408
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
409 /* Return the data array from this row */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
410 var oData = oSettings.aoData.splice( iAODataIndex, 1 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
411
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
412 /* Update the _DT_RowIndex parameter */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
413 for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
414 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
415 if ( oSettings.aoData[i].nTr !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
416 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
417 oSettings.aoData[i].nTr._DT_RowIndex = i;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
418 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
419 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
420
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
421 /* Remove the target row from the search array */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
422 var iDisplayIndex = $.inArray( iAODataIndex, oSettings.aiDisplay );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
423 oSettings.asDataSearch.splice( iDisplayIndex, 1 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
424
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
425 /* Delete from the display arrays */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
426 _fnDeleteIndex( oSettings.aiDisplayMaster, iAODataIndex );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
427 _fnDeleteIndex( oSettings.aiDisplay, iAODataIndex );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
428
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
429 /* If there is a user callback function - call it */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
430 if ( typeof fnCallBack === "function" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
431 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
432 fnCallBack.call( this, oSettings, oData );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
433 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
434
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
435 /* Check for an 'overflow' they case for displaying the table */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
436 if ( oSettings._iDisplayStart >= oSettings.fnRecordsDisplay() )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
437 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
438 oSettings._iDisplayStart -= oSettings._iDisplayLength;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
439 if ( oSettings._iDisplayStart < 0 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
440 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
441 oSettings._iDisplayStart = 0;
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
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
445 if ( bRedraw === undefined || bRedraw )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
446 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
447 _fnCalculateEnd( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
448 _fnDraw( oSettings );
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 return oData;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
452 };
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 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
456 * Restore the table to it's original state in the DOM by removing all of DataTables
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
457 * enhancements, alterations to the DOM structure of the table and event listeners.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
458 * @param {boolean} [bRemove=false] Completely remove the table from the DOM
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
459 * @dtopt API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
460 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
461 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
462 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
463 * // This example is fairly pointless in reality, but shows how fnDestroy can be used
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
464 * var oTable = $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
465 * oTable.fnDestroy();
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 this.fnDestroy = function ( bRemove )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
469 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
470 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
471 var nOrig = oSettings.nTableWrapper.parentNode;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
472 var nBody = oSettings.nTBody;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
473 var i, iLen;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
474
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
475 bRemove = (bRemove===undefined) ? false : bRemove;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
476
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
477 /* Flag to note that the table is currently being destroyed - no action should be taken */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
478 oSettings.bDestroying = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
479
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
480 /* Fire off the destroy callbacks for plug-ins etc */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
481 _fnCallbackFire( oSettings, "aoDestroyCallback", "destroy", [oSettings] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
482
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
483 /* If the table is not being removed, restore the hidden columns */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
484 if ( !bRemove )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
485 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
486 for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
487 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
488 if ( oSettings.aoColumns[i].bVisible === false )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
489 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
490 this.fnSetColumnVis( i, true );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
491 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
492 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
493 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
494
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
495 /* Blitz all DT events */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
496 $(oSettings.nTableWrapper).find('*').andSelf().unbind('.DT');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
497
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
498 /* If there is an 'empty' indicator row, remove it */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
499 $('tbody>tr>td.'+oSettings.oClasses.sRowEmpty, oSettings.nTable).parent().remove();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
500
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
501 /* When scrolling we had to break the table up - restore it */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
502 if ( oSettings.nTable != oSettings.nTHead.parentNode )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
503 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
504 $(oSettings.nTable).children('thead').remove();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
505 oSettings.nTable.appendChild( oSettings.nTHead );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
506 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
507
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
508 if ( oSettings.nTFoot && oSettings.nTable != oSettings.nTFoot.parentNode )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
509 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
510 $(oSettings.nTable).children('tfoot').remove();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
511 oSettings.nTable.appendChild( oSettings.nTFoot );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
512 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
513
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
514 /* Remove the DataTables generated nodes, events and classes */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
515 oSettings.nTable.parentNode.removeChild( oSettings.nTable );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
516 $(oSettings.nTableWrapper).remove();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
517
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
518 oSettings.aaSorting = [];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
519 oSettings.aaSortingFixed = [];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
520 _fnSortingClasses( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
521
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
522 $(_fnGetTrNodes( oSettings )).removeClass( oSettings.asStripeClasses.join(' ') );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
523
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
524 $('th, td', oSettings.nTHead).removeClass( [
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
525 oSettings.oClasses.sSortable,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
526 oSettings.oClasses.sSortableAsc,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
527 oSettings.oClasses.sSortableDesc,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
528 oSettings.oClasses.sSortableNone ].join(' ')
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
529 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
530 if ( oSettings.bJUI )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
531 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
532 $('th span.'+oSettings.oClasses.sSortIcon
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
533 + ', td span.'+oSettings.oClasses.sSortIcon, oSettings.nTHead).remove();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
534
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
535 $('th, td', oSettings.nTHead).each( function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
536 var jqWrapper = $('div.'+oSettings.oClasses.sSortJUIWrapper, this);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
537 var kids = jqWrapper.contents();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
538 $(this).append( kids );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
539 jqWrapper.remove();
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
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
543 /* Add the TR elements back into the table in their original order */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
544 if ( !bRemove && oSettings.nTableReinsertBefore )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
545 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
546 nOrig.insertBefore( oSettings.nTable, oSettings.nTableReinsertBefore );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
547 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
548 else if ( !bRemove )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
549 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
550 nOrig.appendChild( oSettings.nTable );
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 for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
554 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
555 if ( oSettings.aoData[i].nTr !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
556 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
557 nBody.appendChild( oSettings.aoData[i].nTr );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
558 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
559 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
560
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
561 /* Restore the width of the original table */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
562 if ( oSettings.oFeatures.bAutoWidth === true )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
563 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
564 oSettings.nTable.style.width = _fnStringToCss(oSettings.sDestroyWidth);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
565 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
566
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
567 /* If the were originally stripe classes - then we add them back here. Note
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
568 * this is not fool proof (for example if not all rows had stripe classes - but
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
569 * it's a good effort without getting carried away
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
570 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
571 iLen = oSettings.asDestroyStripes.length;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
572 if (iLen)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
573 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
574 var anRows = $(nBody).children('tr');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
575 for ( i=0 ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
576 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
577 anRows.filter(':nth-child(' + iLen + 'n + ' + i + ')').addClass( oSettings.asDestroyStripes[i] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
578 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
579 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
580
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
581 /* Remove the settings object from the settings array */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
582 for ( i=0, iLen=DataTable.settings.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
583 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
584 if ( DataTable.settings[i] == oSettings )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
585 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
586 DataTable.settings.splice( i, 1 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
587 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
588 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
589
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
590 /* End it all */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
591 oSettings = null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
592 oInit = null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
593 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
594
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
595
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
596 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
597 * Redraw the table
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
598 * @param {bool} [bComplete=true] Re-filter and resort (if enabled) the table before the draw.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
599 * @dtopt API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
600 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
601 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
602 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
603 * var oTable = $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
604 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
605 * // Re-draw the table - you wouldn't want to do it here, but it's an example :-)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
606 * oTable.fnDraw();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
607 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
608 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
609 this.fnDraw = function( bComplete )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
610 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
611 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
612 if ( bComplete === false )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
613 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
614 _fnCalculateEnd( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
615 _fnDraw( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
616 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
617 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
618 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
619 _fnReDraw( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
620 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
621 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
622
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
623
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
624 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
625 * Filter the input based on data
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
626 * @param {string} sInput String to filter the table on
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
627 * @param {int|null} [iColumn] Column to limit filtering to
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
628 * @param {bool} [bRegex=false] Treat as regular expression or not
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
629 * @param {bool} [bSmart=true] Perform smart filtering or not
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
630 * @param {bool} [bShowGlobal=true] Show the input global filter in it's input box(es)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
631 * @param {bool} [bCaseInsensitive=true] Do case-insensitive matching (true) or not (false)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
632 * @dtopt API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
633 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
634 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
635 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
636 * var oTable = $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
637 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
638 * // Sometime later - filter...
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
639 * oTable.fnFilter( 'test string' );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
640 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
641 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
642 this.fnFilter = function( sInput, iColumn, bRegex, bSmart, bShowGlobal, bCaseInsensitive )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
643 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
644 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
645
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
646 if ( !oSettings.oFeatures.bFilter )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
647 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
648 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
649 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
650
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
651 if ( bRegex === undefined || bRegex === null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
652 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
653 bRegex = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
654 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
655
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
656 if ( bSmart === undefined || bSmart === null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
657 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
658 bSmart = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
659 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
660
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
661 if ( bShowGlobal === undefined || bShowGlobal === null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
662 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
663 bShowGlobal = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
664 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
665
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
666 if ( bCaseInsensitive === undefined || bCaseInsensitive === null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
667 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
668 bCaseInsensitive = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
669 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
670
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
671 if ( iColumn === undefined || iColumn === null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
672 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
673 /* Global filter */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
674 _fnFilterComplete( oSettings, {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
675 "sSearch":sInput+"",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
676 "bRegex": bRegex,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
677 "bSmart": bSmart,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
678 "bCaseInsensitive": bCaseInsensitive
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
679 }, 1 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
680
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
681 if ( bShowGlobal && oSettings.aanFeatures.f )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
682 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
683 var n = oSettings.aanFeatures.f;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
684 for ( var i=0, iLen=n.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
685 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
686 // IE9 throws an 'unknown error' if document.activeElement is used
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
687 // inside an iframe or frame...
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
688 try {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
689 if ( n[i]._DT_Input != document.activeElement )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
690 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
691 $(n[i]._DT_Input).val( sInput );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
692 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
693 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
694 catch ( e ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
695 $(n[i]._DT_Input).val( sInput );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
696 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
697 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
698 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
699 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
700 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
701 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
702 /* Single column filter */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
703 $.extend( oSettings.aoPreSearchCols[ iColumn ], {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
704 "sSearch": sInput+"",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
705 "bRegex": bRegex,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
706 "bSmart": bSmart,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
707 "bCaseInsensitive": bCaseInsensitive
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
708 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
709 _fnFilterComplete( oSettings, oSettings.oPreviousSearch, 1 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
710 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
711 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
712
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
713
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
714 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
715 * Get the data for the whole table, an individual row or an individual cell based on the
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
716 * provided parameters.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
717 * @param {int|node} [mRow] A TR row node, TD/TH cell node or an integer. If given as
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
718 * a TR node then the data source for the whole row will be returned. If given as a
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
719 * TD/TH cell node then iCol will be automatically calculated and the data for the
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
720 * cell returned. If given as an integer, then this is treated as the aoData internal
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
721 * data index for the row (see fnGetPosition) and the data for that row used.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
722 * @param {int} [iCol] Optional column index that you want the data of.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
723 * @returns {array|object|string} If mRow is undefined, then the data for all rows is
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
724 * returned. If mRow is defined, just data for that row, and is iCol is
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
725 * defined, only data for the designated cell is returned.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
726 * @dtopt API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
727 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
728 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
729 * // Row data
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
730 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
731 * oTable = $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
732 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
733 * oTable.$('tr').click( function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
734 * var data = oTable.fnGetData( this );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
735 * // ... do something with the array / object of data for the row
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
736 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
737 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
738 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
739 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
740 * // Individual cell data
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
741 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
742 * oTable = $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
743 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
744 * oTable.$('td').click( function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
745 * var sData = oTable.fnGetData( this );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
746 * alert( 'The cell clicked on had the value of '+sData );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
747 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
748 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
749 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
750 this.fnGetData = function( mRow, iCol )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
751 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
752 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
753
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
754 if ( mRow !== undefined )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
755 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
756 var iRow = mRow;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
757 if ( typeof mRow === 'object' )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
758 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
759 var sNode = mRow.nodeName.toLowerCase();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
760 if (sNode === "tr" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
761 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
762 iRow = _fnNodeToDataIndex(oSettings, mRow);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
763 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
764 else if ( sNode === "td" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
765 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
766 iRow = _fnNodeToDataIndex(oSettings, mRow.parentNode);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
767 iCol = _fnNodeToColumnIndex( oSettings, iRow, mRow );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
768 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
769 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
770
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
771 if ( iCol !== undefined )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
772 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
773 return _fnGetCellData( oSettings, iRow, iCol, '' );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
774 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
775 return (oSettings.aoData[iRow]!==undefined) ?
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
776 oSettings.aoData[iRow]._aData : null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
777 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
778 return _fnGetDataMaster( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
779 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
780
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
781
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
782 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
783 * Get an array of the TR nodes that are used in the table's body. Note that you will
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
784 * typically want to use the '$' API method in preference to this as it is more
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
785 * flexible.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
786 * @param {int} [iRow] Optional row index for the TR element you want
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
787 * @returns {array|node} If iRow is undefined, returns an array of all TR elements
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
788 * in the table's body, or iRow is defined, just the TR element requested.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
789 * @dtopt API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
790 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
791 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
792 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
793 * var oTable = $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
794 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
795 * // Get the nodes from the table
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
796 * var nNodes = oTable.fnGetNodes( );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
797 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
798 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
799 this.fnGetNodes = function( iRow )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
800 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
801 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
802
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
803 if ( iRow !== undefined ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
804 return (oSettings.aoData[iRow]!==undefined) ?
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
805 oSettings.aoData[iRow].nTr : null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
806 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
807 return _fnGetTrNodes( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
808 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
809
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
810
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
811 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
812 * Get the array indexes of a particular cell from it's DOM element
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
813 * and column index including hidden columns
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
814 * @param {node} nNode this can either be a TR, TD or TH in the table's body
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
815 * @returns {int} If nNode is given as a TR, then a single index is returned, or
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
816 * if given as a cell, an array of [row index, column index (visible),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
817 * column index (all)] is given.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
818 * @dtopt API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
819 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
820 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
821 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
822 * $('#example tbody td').click( function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
823 * // Get the position of the current data from the node
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
824 * var aPos = oTable.fnGetPosition( this );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
825 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
826 * // Get the data array for this row
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
827 * var aData = oTable.fnGetData( aPos[0] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
828 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
829 * // Update the data array and return the value
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
830 * aData[ aPos[1] ] = 'clicked';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
831 * this.innerHTML = 'clicked';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
832 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
833 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
834 * // Init DataTables
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
835 * oTable = $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
836 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
837 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
838 this.fnGetPosition = function( nNode )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
839 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
840 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
841 var sNodeName = nNode.nodeName.toUpperCase();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
842
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
843 if ( sNodeName == "TR" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
844 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
845 return _fnNodeToDataIndex(oSettings, nNode);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
846 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
847 else if ( sNodeName == "TD" || sNodeName == "TH" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
848 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
849 var iDataIndex = _fnNodeToDataIndex( oSettings, nNode.parentNode );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
850 var iColumnIndex = _fnNodeToColumnIndex( oSettings, iDataIndex, nNode );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
851 return [ iDataIndex, _fnColumnIndexToVisible(oSettings, iColumnIndex ), iColumnIndex ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
852 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
853 return null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
854 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
855
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
856
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
857 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
858 * Check to see if a row is 'open' or not.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
859 * @param {node} nTr the table row to check
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
860 * @returns {boolean} true if the row is currently open, false otherwise
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
861 * @dtopt API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
862 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
863 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
864 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
865 * var oTable;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
866 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
867 * // 'open' an information row when a row is clicked on
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
868 * $('#example tbody tr').click( function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
869 * if ( oTable.fnIsOpen(this) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
870 * oTable.fnClose( this );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
871 * } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
872 * oTable.fnOpen( this, "Temporary row opened", "info_row" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
873 * }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
874 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
875 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
876 * oTable = $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
877 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
878 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
879 this.fnIsOpen = function( nTr )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
880 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
881 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
882 var aoOpenRows = oSettings.aoOpenRows;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
883
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
884 for ( var i=0 ; i<oSettings.aoOpenRows.length ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
885 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
886 if ( oSettings.aoOpenRows[i].nParent == nTr )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
887 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
888 return true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
889 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
890 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
891 return false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
892 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
893
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
894
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
895 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
896 * This function will place a new row directly after a row which is currently
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
897 * on display on the page, with the HTML contents that is passed into the
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
898 * function. This can be used, for example, to ask for confirmation that a
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
899 * particular record should be deleted.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
900 * @param {node} nTr The table row to 'open'
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
901 * @param {string|node|jQuery} mHtml The HTML to put into the row
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
902 * @param {string} sClass Class to give the new TD cell
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
903 * @returns {node} The row opened. Note that if the table row passed in as the
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
904 * first parameter, is not found in the table, this method will silently
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
905 * return.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
906 * @dtopt API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
907 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
908 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
909 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
910 * var oTable;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
911 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
912 * // 'open' an information row when a row is clicked on
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
913 * $('#example tbody tr').click( function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
914 * if ( oTable.fnIsOpen(this) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
915 * oTable.fnClose( this );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
916 * } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
917 * oTable.fnOpen( this, "Temporary row opened", "info_row" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
918 * }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
919 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
920 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
921 * oTable = $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
922 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
923 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
924 this.fnOpen = function( nTr, mHtml, sClass )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
925 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
926 /* Find settings from table node */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
927 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
928
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
929 /* Check that the row given is in the table */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
930 var nTableRows = _fnGetTrNodes( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
931 if ( $.inArray(nTr, nTableRows) === -1 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
932 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
933 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
934 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
935
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
936 /* the old open one if there is one */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
937 this.fnClose( nTr );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
938
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
939 var nNewRow = document.createElement("tr");
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
940 var nNewCell = document.createElement("td");
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
941 nNewRow.appendChild( nNewCell );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
942 nNewCell.className = sClass;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
943 nNewCell.colSpan = _fnVisbleColumns( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
944
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
945 if (typeof mHtml === "string")
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
946 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
947 nNewCell.innerHTML = mHtml;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
948 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
949 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
950 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
951 $(nNewCell).html( mHtml );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
952 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
953
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
954 /* If the nTr isn't on the page at the moment - then we don't insert at the moment */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
955 var nTrs = $('tr', oSettings.nTBody);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
956 if ( $.inArray(nTr, nTrs) != -1 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
957 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
958 $(nNewRow).insertAfter(nTr);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
959 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
960
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
961 oSettings.aoOpenRows.push( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
962 "nTr": nNewRow,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
963 "nParent": nTr
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
964 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
965
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
966 return nNewRow;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
967 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
968
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
969
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
970 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
971 * Change the pagination - provides the internal logic for pagination in a simple API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
972 * function. With this function you can have a DataTables table go to the next,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
973 * previous, first or last pages.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
974 * @param {string|int} mAction Paging action to take: "first", "previous", "next" or "last"
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
975 * or page number to jump to (integer), note that page 0 is the first page.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
976 * @param {bool} [bRedraw=true] Redraw the table or not
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
977 * @dtopt API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
978 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
979 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
980 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
981 * var oTable = $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
982 * oTable.fnPageChange( 'next' );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
983 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
984 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
985 this.fnPageChange = function ( mAction, bRedraw )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
986 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
987 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
988 _fnPageChange( oSettings, mAction );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
989 _fnCalculateEnd( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
990
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
991 if ( bRedraw === undefined || bRedraw )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
992 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
993 _fnDraw( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
994 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
995 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
996
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
997
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
998 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
999 * Show a particular column
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1000 * @param {int} iCol The column whose display should be changed
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1001 * @param {bool} bShow Show (true) or hide (false) the column
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1002 * @param {bool} [bRedraw=true] Redraw the table or not
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1003 * @dtopt API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1004 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1005 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1006 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1007 * var oTable = $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1008 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1009 * // Hide the second column after initialisation
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1010 * oTable.fnSetColumnVis( 1, false );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1011 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1012 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1013 this.fnSetColumnVis = function ( iCol, bShow, bRedraw )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1014 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1015 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1016 var i, iLen;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1017 var aoColumns = oSettings.aoColumns;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1018 var aoData = oSettings.aoData;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1019 var nTd, bAppend, iBefore;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1020
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1021 /* No point in doing anything if we are requesting what is already true */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1022 if ( aoColumns[iCol].bVisible == bShow )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1023 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1024 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1025 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1026
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1027 /* Show the column */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1028 if ( bShow )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1029 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1030 var iInsert = 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1031 for ( i=0 ; i<iCol ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1032 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1033 if ( aoColumns[i].bVisible )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1034 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1035 iInsert++;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1036 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1037 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1038
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1039 /* Need to decide if we should use appendChild or insertBefore */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1040 bAppend = (iInsert >= _fnVisbleColumns( oSettings ));
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1041
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1042 /* Which coloumn should we be inserting before? */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1043 if ( !bAppend )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1044 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1045 for ( i=iCol ; i<aoColumns.length ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1046 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1047 if ( aoColumns[i].bVisible )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1048 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1049 iBefore = i;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1050 break;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1051 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1052 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1053 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1054
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1055 for ( i=0, iLen=aoData.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1056 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1057 if ( aoData[i].nTr !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1058 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1059 if ( bAppend )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1060 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1061 aoData[i].nTr.appendChild(
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1062 aoData[i]._anHidden[iCol]
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1063 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1064 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1065 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1066 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1067 aoData[i].nTr.insertBefore(
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1068 aoData[i]._anHidden[iCol],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1069 _fnGetTdNodes( oSettings, i )[iBefore] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1070 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1071 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1072 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1073 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1074 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1075 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1076 /* Remove a column from display */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1077 for ( i=0, iLen=aoData.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1078 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1079 if ( aoData[i].nTr !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1080 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1081 nTd = _fnGetTdNodes( oSettings, i )[iCol];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1082 aoData[i]._anHidden[iCol] = nTd;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1083 nTd.parentNode.removeChild( nTd );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1084 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1085 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1086 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1087
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1088 /* Clear to set the visible flag */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1089 aoColumns[iCol].bVisible = bShow;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1090
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1091 /* Redraw the header and footer based on the new column visibility */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1092 _fnDrawHead( oSettings, oSettings.aoHeader );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1093 if ( oSettings.nTFoot )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1094 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1095 _fnDrawHead( oSettings, oSettings.aoFooter );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1096 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1097
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1098 /* If there are any 'open' rows, then we need to alter the colspan for this col change */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1099 for ( i=0, iLen=oSettings.aoOpenRows.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1100 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1101 oSettings.aoOpenRows[i].nTr.colSpan = _fnVisbleColumns( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1102 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1103
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1104 /* Do a redraw incase anything depending on the table columns needs it
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1105 * (built-in: scrolling)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1106 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1107 if ( bRedraw === undefined || bRedraw )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1108 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1109 _fnAdjustColumnSizing( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1110 _fnDraw( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1111 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1112
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1113 _fnSaveState( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1114 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1115
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1116
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1117 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1118 * Get the settings for a particular table for external manipulation
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1119 * @returns {object} DataTables settings object. See
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1120 * {@link DataTable.models.oSettings}
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1121 * @dtopt API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1122 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1123 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1124 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1125 * var oTable = $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1126 * var oSettings = oTable.fnSettings();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1127 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1128 * // Show an example parameter from the settings
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1129 * alert( oSettings._iDisplayStart );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1130 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1131 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1132 this.fnSettings = function()
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1133 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1134 return _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1135 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1136
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1137
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1138 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1139 * Sort the table by a particular column
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1140 * @param {int} iCol the data index to sort on. Note that this will not match the
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1141 * 'display index' if you have hidden data entries
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1142 * @dtopt API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1143 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1144 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1145 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1146 * var oTable = $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1147 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1148 * // Sort immediately with columns 0 and 1
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1149 * oTable.fnSort( [ [0,'asc'], [1,'asc'] ] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1150 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1151 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1152 this.fnSort = function( aaSort )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1153 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1154 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1155 oSettings.aaSorting = aaSort;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1156 _fnSort( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1157 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1158
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1159
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1160 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1161 * Attach a sort listener to an element for a given column
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1162 * @param {node} nNode the element to attach the sort listener to
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1163 * @param {int} iColumn the column that a click on this node will sort on
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1164 * @param {function} [fnCallback] callback function when sort is run
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1165 * @dtopt API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1166 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1167 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1168 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1169 * var oTable = $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1170 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1171 * // Sort on column 1, when 'sorter' is clicked on
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1172 * oTable.fnSortListener( document.getElementById('sorter'), 1 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1173 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1174 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1175 this.fnSortListener = function( nNode, iColumn, fnCallback )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1176 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1177 _fnSortAttachListener( _fnSettingsFromNode( this[DataTable.ext.iApiIndex] ), nNode, iColumn,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1178 fnCallback );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1179 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1180
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1181
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1182 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1183 * Update a table cell or row - this method will accept either a single value to
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1184 * update the cell with, an array of values with one element for each column or
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1185 * an object in the same format as the original data source. The function is
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1186 * self-referencing in order to make the multi column updates easier.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1187 * @param {object|array|string} mData Data to update the cell/row with
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1188 * @param {node|int} mRow TR element you want to update or the aoData index
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1189 * @param {int} [iColumn] The column to update (not used of mData is an array or object)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1190 * @param {bool} [bRedraw=true] Redraw the table or not
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1191 * @param {bool} [bAction=true] Perform pre-draw actions or not
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1192 * @returns {int} 0 on success, 1 on error
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1193 * @dtopt API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1194 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1195 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1196 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1197 * var oTable = $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1198 * oTable.fnUpdate( 'Example update', 0, 0 ); // Single cell
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1199 * oTable.fnUpdate( ['a', 'b', 'c', 'd', 'e'], 1, 0 ); // Row
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1200 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1201 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1202 this.fnUpdate = function( mData, mRow, iColumn, bRedraw, bAction )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1203 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1204 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1205 var i, iLen, sDisplay;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1206 var iRow = (typeof mRow === 'object') ?
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1207 _fnNodeToDataIndex(oSettings, mRow) : mRow;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1208
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1209 if ( $.isArray(mData) && iColumn === undefined )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1210 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1211 /* Array update - update the whole row */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1212 oSettings.aoData[iRow]._aData = mData.slice();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1213
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1214 /* Flag to the function that we are recursing */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1215 for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1216 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1217 this.fnUpdate( _fnGetCellData( oSettings, iRow, i ), iRow, i, false, false );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1218 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1219 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1220 else if ( $.isPlainObject(mData) && iColumn === undefined )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1221 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1222 /* Object update - update the whole row - assume the developer gets the object right */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1223 oSettings.aoData[iRow]._aData = $.extend( true, {}, mData );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1224
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1225 for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1226 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1227 this.fnUpdate( _fnGetCellData( oSettings, iRow, i ), iRow, i, false, false );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1228 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1229 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1230 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1231 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1232 /* Individual cell update */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1233 _fnSetCellData( oSettings, iRow, iColumn, mData );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1234 sDisplay = _fnGetCellData( oSettings, iRow, iColumn, 'display' );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1235
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1236 var oCol = oSettings.aoColumns[iColumn];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1237 if ( oCol.fnRender !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1238 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1239 sDisplay = _fnRender( oSettings, iRow, iColumn );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1240 if ( oCol.bUseRendered )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1241 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1242 _fnSetCellData( oSettings, iRow, iColumn, sDisplay );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1243 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1244 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1245
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1246 if ( oSettings.aoData[iRow].nTr !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1247 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1248 /* Do the actual HTML update */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1249 _fnGetTdNodes( oSettings, iRow )[iColumn].innerHTML = sDisplay;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1250 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1251 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1252
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1253 /* Modify the search index for this row (strictly this is likely not needed, since fnReDraw
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1254 * will rebuild the search array - however, the redraw might be disabled by the user)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1255 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1256 var iDisplayIndex = $.inArray( iRow, oSettings.aiDisplay );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1257 oSettings.asDataSearch[iDisplayIndex] = _fnBuildSearchRow(
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1258 oSettings,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1259 _fnGetRowData( oSettings, iRow, 'filter', _fnGetColumns( oSettings, 'bSearchable' ) )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1260 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1261
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1262 /* Perform pre-draw actions */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1263 if ( bAction === undefined || bAction )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1264 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1265 _fnAdjustColumnSizing( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1266 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1267
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1268 /* Redraw the table */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1269 if ( bRedraw === undefined || bRedraw )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1270 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1271 _fnReDraw( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1272 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1273 return 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1274 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1275
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1276
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1277 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1278 * Provide a common method for plug-ins to check the version of DataTables being used, in order
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1279 * to ensure compatibility.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1280 * @param {string} sVersion Version string to check for, in the format "X.Y.Z". Note that the
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1281 * formats "X" and "X.Y" are also acceptable.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1282 * @returns {boolean} true if this version of DataTables is greater or equal to the required
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1283 * version, or false if this version of DataTales is not suitable
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1284 * @method
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1285 * @dtopt API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1286 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1287 * @example
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1288 * $(document).ready(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1289 * var oTable = $('#example').dataTable();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1290 * alert( oTable.fnVersionCheck( '1.9.0' ) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1291 * } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1292 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1293 this.fnVersionCheck = DataTable.ext.fnVersionCheck;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1294