Subversion-Projekte lars-tiefland.cienc

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
8 lars 1
/**
2
 * Return an array of table values from a particular column, with various
3
 * filtering options.
4
 *
5
 * DataTables 1.10+ provides the `dt-api column().data()` method, built-in to
6
 * the core, to provide this ability. As such, this method is marked deprecated,
7
 * but is available for use with legacy version of DataTables. Please use the
8
 * new API if you are used DataTables 1.10 or newer.
9
 *
10
 *  @name fnGetColumnData
11
 *  @summary Get the data from a column
12
 *  @author [Benedikt Forchhammer](http://mind2.de)
13
 *  @deprecated
14
 *
15
 *  @param {integer} iColumn Column to get data from
16
 *  @param {boolean} [bFiltered=true] Reduce the data set to only unique values
17
 *  @param {boolean} [bUnique=true] Get data from filter results only
18
 *  @param {boolean} [bIgnoreEmpty=true] Remove data elements which are empty
19
 *  @returns {array} Array of data from the column
20
 *
21
 *  @example
22
 *    var table = $('#example').dataTable();
23
 *    table.fnGetColumnData( 3 );
24
 */
25
 
26
jQuery.fn.dataTableExt.oApi.fnGetColumnData = function ( oSettings, iColumn, bUnique, bFiltered, bIgnoreEmpty ) {
27
	// check that we have a column id
28
	if ( typeof iColumn == "undefined" ) {
29
		return [];
30
	}
31
 
32
	// by default we only wany unique data
33
	if ( typeof bUnique == "undefined" ) {
34
		bUnique = true;
35
	}
36
 
37
	// by default we do want to only look at filtered data
38
	if ( typeof bFiltered == "undefined" ) {
39
		bFiltered = true;
40
	}
41
 
42
	// by default we do not wany to include empty values
43
	if ( typeof bIgnoreEmpty == "undefined" ) {
44
		bIgnoreEmpty = true;
45
	}
46
 
47
	// list of rows which we're going to loop through
48
	var aiRows;
49
 
50
	// use only filtered rows
51
	if (bFiltered === true) {
52
		aiRows = oSettings.aiDisplay;
53
	}
54
	// use all rows
55
	else {
56
		aiRows = oSettings.aiDisplayMaster; // all row numbers
57
	}
58
 
59
	// set up data array
60
	var asResultData = [];
61
 
62
	for (var i=0,c=aiRows.length; i<c; i++) {
63
		var iRow = aiRows[i];
64
		var sValue = this.fnGetData(iRow, iColumn);
65
 
66
		// ignore empty values?
67
		if (bIgnoreEmpty === true && sValue.length === 0) {
68
			continue;
69
		}
70
 
71
		// ignore unique values?
72
		else if (bUnique === true && jQuery.inArray(sValue, asResultData) > -1) {
73
			continue;
74
		}
75
 
76
		// else push the value onto the result data array
77
		else {
78
			asResultData.push(sValue);
79
		}
80
	}
81
 
82
	return asResultData;
83
};