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

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
4 lars 1
/**
2
 * Creates `rowspan` cells in a column when there are two or more cells in a
3
 * row with the same content, effectively grouping them together visually.
4
 *
5
 * **Note** - this plug-in currently only operates correctly with
6
 * **server-side processing**.
7
 *
8
 *  @name fnFakeRowspan
9
 *  @summary Create a rowspan for cells which share data
10
 *  @author Fredrik Wendel
11
 *
12
 *  @param {interger} iColumn Column index to have row span
13
 *  @param {boolean} [bCaseSensitive=true] If the data check should be case
14
 *    sensitive or not.
15
 *  @returns {jQuery} jQuery instance
16
 *
17
 *  @example
18
 *    $('#example').dataTable().fnFakeRowspan(3);
19
 */
20
 
21
jQuery.fn.dataTableExt.oApi.fnFakeRowspan = function ( oSettings, iColumn, bCaseSensitive ) {
22
	/* Fail silently on missing/errorenous parameter data. */
23
	if (isNaN(iColumn)) {
24
		return false;
25
	}
26
 
27
	if (iColumn < 0 || iColumn > oSettings.aoColumns.length-1) {
28
		alert ('Invalid column number choosen, must be between 0 and ' + (oSettings.aoColumns.length-1));
29
		return false;
30
	}
31
 
32
	bCaseSensitive = (typeof(bCaseSensitive) != 'boolean' ? true : bCaseSensitive);
33
 
34
	function fakeRowspan () {
35
		var firstOccurance = null,
36
			value = null,
37
			rowspan = 0;
38
		jQuery.each(oSettings.aoData, function (i, oData) {
39
			var val = oData._aData[iColumn],
40
				cell = oData.nTr.childNodes[iColumn];
41
			/* Use lowercase comparison if not case-sensitive. */
42
			if (!bCaseSensitive) {
43
				val = val.toLowerCase();
44
			}
45
			/* Reset values on new cell data. */
46
			if (val != value) {
47
				value = val;
48
				firstOccurance = cell;
49
				rowspan = 0;
50
			}
51
 
52
			if (val == value) {
53
				rowspan++;
54
			}
55
 
56
			if (firstOccurance !== null && val == value && rowspan > 1) {
57
				oData.nTr.removeChild(cell);
58
				firstOccurance.rowSpan = rowspan;
59
			}
60
		});
61
	}
62
 
63
	oSettings.aoDrawCallback.push({ "fn": fakeRowspan, "sName": "fnFakeRowspan" });
64
 
65
	return this;
66
};