1 |
|
2 |
|
3 |
/** |
4 |
* Draw the table for the first time, adding all required features |
5 |
* @param {object} oSettings dataTables settings object |
6 |
* @memberof DataTable#oApi |
7 |
*/ |
8 |
function _fnInitialise ( oSettings ) |
9 |
{ |
10 |
var i, iLen, iAjaxStart=oSettings.iInitDisplayStart; |
11 |
|
12 |
/* Ensure that the table data is fully initialised */ |
13 |
if ( oSettings.bInitialised === false ) |
14 |
{ |
15 |
setTimeout( function(){ _fnInitialise( oSettings ); }, 200 ); |
16 |
return; |
17 |
} |
18 |
|
19 |
/* Show the display HTML options */ |
20 |
_fnAddOptionsHtml( oSettings ); |
21 |
|
22 |
/* Build and draw the header / footer for the table */ |
23 |
_fnBuildHead( oSettings ); |
24 |
_fnDrawHead( oSettings, oSettings.aoHeader ); |
25 |
if ( oSettings.nTFoot ) |
26 |
{ |
27 |
_fnDrawHead( oSettings, oSettings.aoFooter ); |
28 |
} |
29 |
|
30 |
/* Okay to show that something is going on now */ |
31 |
_fnProcessingDisplay( oSettings, true ); |
32 |
|
33 |
/* Calculate sizes for columns */ |
34 |
if ( oSettings.oFeatures.bAutoWidth ) |
35 |
{ |
36 |
_fnCalculateColumnWidths( oSettings ); |
37 |
} |
38 |
|
39 |
for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ ) |
40 |
{ |
41 |
if ( oSettings.aoColumns[i].sWidth !== null ) |
42 |
{ |
43 |
oSettings.aoColumns[i].nTh.style.width = _fnStringToCss( oSettings.aoColumns[i].sWidth ); |
44 |
} |
45 |
} |
46 |
|
47 |
/* If there is default sorting required - let's do it. The sort function will do the |
48 |
* drawing for us. Otherwise we draw the table regardless of the Ajax source - this allows |
49 |
* the table to look initialised for Ajax sourcing data (show 'loading' message possibly) |
50 |
*/ |
51 |
if ( oSettings.oFeatures.bSort ) |
52 |
{ |
53 |
_fnSort( oSettings ); |
54 |
} |
55 |
else if ( oSettings.oFeatures.bFilter ) |
56 |
{ |
57 |
_fnFilterComplete( oSettings, oSettings.oPreviousSearch ); |
58 |
} |
59 |
else |
60 |
{ |
61 |
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice(); |
62 |
_fnCalculateEnd( oSettings ); |
63 |
_fnDraw( oSettings ); |
64 |
} |
65 |
|
66 |
/* if there is an ajax source load the data */ |
67 |
if ( oSettings.sAjaxSource !== null && !oSettings.oFeatures.bServerSide ) |
68 |
{ |
69 |
var aoData = []; |
70 |
_fnServerParams( oSettings, aoData ); |
71 |
oSettings.fnServerData.call( oSettings.oInstance, oSettings.sAjaxSource, aoData, function(json) { |
72 |
var aData = (oSettings.sAjaxDataProp !== "") ? |
73 |
_fnGetObjectDataFn( oSettings.sAjaxDataProp )(json) : json; |
74 |
|
75 |
/* Got the data - add it to the table */ |
76 |
for ( i=0 ; i<aData.length ; i++ ) |
77 |
{ |
78 |
_fnAddData( oSettings, aData[i] ); |
79 |
} |
80 |
|
81 |
/* Reset the init display for cookie saving. We've already done a filter, and |
82 |
* therefore cleared it before. So we need to make it appear 'fresh' |
83 |
*/ |
84 |
oSettings.iInitDisplayStart = iAjaxStart; |
85 |
|
86 |
if ( oSettings.oFeatures.bSort ) |
87 |
{ |
88 |
_fnSort( oSettings ); |
89 |
} |
90 |
else |
91 |
{ |
92 |
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice(); |
93 |
_fnCalculateEnd( oSettings ); |
94 |
_fnDraw( oSettings ); |
95 |
} |
96 |
|
97 |
_fnProcessingDisplay( oSettings, false ); |
98 |
_fnInitComplete( oSettings, json ); |
99 |
}, oSettings ); |
100 |
return; |
101 |
} |
102 |
|
103 |
/* Server-side processing initialisation complete is done at the end of _fnDraw */ |
104 |
if ( !oSettings.oFeatures.bServerSide ) |
105 |
{ |
106 |
_fnProcessingDisplay( oSettings, false ); |
107 |
_fnInitComplete( oSettings ); |
108 |
} |
109 |
} |
110 |
|
111 |
|
112 |
/** |
113 |
* Draw the table for the first time, adding all required features |
114 |
* @param {object} oSettings dataTables settings object |
115 |
* @param {object} [json] JSON from the server that completed the table, if using Ajax source |
116 |
* with client-side processing (optional) |
117 |
* @memberof DataTable#oApi |
118 |
*/ |
119 |
function _fnInitComplete ( oSettings, json ) |
120 |
{ |
121 |
oSettings._bInitComplete = true; |
122 |
_fnCallbackFire( oSettings, 'aoInitComplete', 'init', [oSettings, json] ); |
123 |
} |
124 |
|
125 |
|
126 |
/** |
127 |
* Language compatibility - when certain options are given, and others aren't, we |
128 |
* need to duplicate the values over, in order to provide backwards compatibility |
129 |
* with older language files. |
130 |
* @param {object} oSettings dataTables settings object |
131 |
* @memberof DataTable#oApi |
132 |
*/ |
133 |
function _fnLanguageCompat( oLanguage ) |
134 |
{ |
135 |
var oDefaults = DataTable.defaults.oLanguage; |
136 |
|
137 |
/* Backwards compatibility - if there is no sEmptyTable given, then use the same as |
138 |
* sZeroRecords - assuming that is given. |
139 |
*/ |
140 |
if ( !oLanguage.sEmptyTable && oLanguage.sZeroRecords && |
141 |
oDefaults.sEmptyTable === "No data available in table" ) |
142 |
{ |
143 |
_fnMap( oLanguage, oLanguage, 'sZeroRecords', 'sEmptyTable' ); |
144 |
} |
145 |
|
146 |
/* Likewise with loading records */ |
147 |
if ( !oLanguage.sLoadingRecords && oLanguage.sZeroRecords && |
148 |
oDefaults.sLoadingRecords === "Loading..." ) |
149 |
{ |
150 |
_fnMap( oLanguage, oLanguage, 'sZeroRecords', 'sLoadingRecords' ); |
151 |
} |
152 |
} |