Subversion-Projekte lars-tiefland.webanos.zeldi.de

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
4 lars 1
/**
2
 * By default DataTables only uses the sAjaxSource variable at initialisation
3
 * time, however it can be useful to re-read an Ajax source and have the table
4
 * update. Typically you would need to use the `fnClearTable()` and
5
 * `fnAddData()` functions, however this wraps it all up in a single function
6
 * call.
7
 *
8
 * DataTables 1.10 provides the `dt-api ajax.url()` and `dt-api ajax.reload()`
9
 * methods, built-in, to give the same functionality as this plug-in. As such
10
 * this method is marked deprecated, but is available for use with legacy
11
 * version of DataTables. Please use the new API if you are used DataTables 1.10
12
 * or newer.
13
 *
14
 *  @name fnReloadAjax
15
 *  @summary Reload the table's data from the Ajax source
16
 *  @author [Allan Jardine](http://sprymedia.co.uk)
17
 *  @deprecated
18
 *
19
 *  @param {string} [sNewSource] URL to get the data from. If not give, the
20
 *    previously used URL is used.
21
 *  @param {function} [fnCallback] Callback that is executed when the table has
22
 *    redrawn with the new data
23
 *  @param {boolean} [bStandingRedraw=false] Standing redraw (don't changing the
24
 *      paging)
25
 *
26
 *  @example
27
 *    var table = $('#example').dataTable();
28
 *
29
 *    // Example call to load a new file
30
 *    table.fnReloadAjax( 'media/examples_support/json_source2.txt' );
31
 *
32
 *    // Example call to reload from original file
33
 *    table.fnReloadAjax();
34
 */
35
 
36
jQuery.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback, bStandingRedraw )
37
{
38
	// DataTables 1.10 compatibility - if 1.10 then `versionCheck` exists.
39
	// 1.10's API has ajax reloading built in, so we use those abilities
40
	// directly.
41
	if ( jQuery.fn.dataTable.versionCheck ) {
42
		var api = new jQuery.fn.dataTable.Api( oSettings );
43
 
44
		if ( sNewSource ) {
45
			api.ajax.url( sNewSource ).load( fnCallback, !bStandingRedraw );
46
		}
47
		else {
48
			api.ajax.reload( fnCallback, !bStandingRedraw );
49
		}
50
		return;
51
	}
52
 
53
	if ( sNewSource !== undefined && sNewSource !== null ) {
54
		oSettings.sAjaxSource = sNewSource;
55
	}
56
 
57
	// Server-side processing should just call fnDraw
58
	if ( oSettings.oFeatures.bServerSide ) {
59
		this.fnDraw();
60
		return;
61
	}
62
 
63
	this.oApi._fnProcessingDisplay( oSettings, true );
64
	var that = this;
65
	var iStart = oSettings._iDisplayStart;
66
	var aData = [];
67
 
68
	this.oApi._fnServerParams( oSettings, aData );
69
 
70
	oSettings.fnServerData.call( oSettings.oInstance, oSettings.sAjaxSource, aData, function(json) {
71
		/* Clear the old information from the table */
72
		that.oApi._fnClearTable( oSettings );
73
 
74
		/* Got the data - add it to the table */
75
		var aData =  (oSettings.sAjaxDataProp !== "") ?
76
			that.oApi._fnGetObjectDataFn( oSettings.sAjaxDataProp )( json ) : json;
77
 
78
		for ( var i=0 ; i<aData.length ; i++ )
79
		{
80
			that.oApi._fnAddData( oSettings, aData[i] );
81
		}
82
 
83
		oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
84
 
85
		that.fnDraw();
86
 
87
		if ( bStandingRedraw === true )
88
		{
89
			oSettings._iDisplayStart = iStart;
90
			that.oApi._fnCalculateEnd( oSettings );
91
			that.fnDraw( false );
92
		}
93
 
94
		that.oApi._fnProcessingDisplay( oSettings, false );
95
 
96
		/* Callback user function - for event handlers etc */
97
		if ( typeof fnCallback == 'function' && fnCallback !== null )
98
		{
99
			fnCallback( oSettings );
100
		}
101
	}, oSettings );
102
};