File: ids.js

package info (click to toggle)
datatables.js 1.10.21%2Bdfsg-2%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 22,604 kB
  • sloc: javascript: 64,254; xml: 10,441; php: 4,623; sh: 523; makefile: 21
file content (80 lines) | stat: -rw-r--r-- 1,853 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// DATA_TEMPLATE: empty_table
oTest.fnStart( "Row ids" );

$(document).ready( function () {
	var table = $('#example').DataTable( {
		"ajax": "../../../examples/ajax/data/objects.txt",
		"deferRender": true,
		"rowId": 'name',
		"columns": [
			{ "data": "name" },
			{ "data": "position" },
			{ "data": "office" },
			{ "data": "extn" },
			{ "data": "start_date" },
			{ "data": "salary" }
		]
	} );
	
	/* Basic checks */
	oTest.fnWaitTest( 
		"Table draws",
		null,
		function () { return $('tbody td:eq(0)').text() === 'Airi Satou'; }
	);
	
	oTest.fnTest( 
		"First row has an ID assigned",
		null,
		function () { return $('tbody tr:eq(0)').attr('id') === 'Airi Satou'; }
	);
	
	oTest.fnTest( 
		"Can select first row by ID via API",
		null,
		function () { return table.row('#Airi Satou').data().name === 'Airi Satou'; }
	);
	
	oTest.fnTest( 
		"Can select second row by ID via API",
		null,
		function () { return table.row('#Angelica Ramos').data().extn === '5797'; }
	);
	
	oTest.fnTest( 
		"Can select 11th row (deferred rendering) by ID via API - node doesn't exist",
		null,
		function () { return table.row('#Charde Marshall').data().extn === '6741'; }
	);
	
	oTest.fnTest( 
		"Get id for a row",
		null,
		function () { return table.row('#Dai Rios').id() === 'Dai Rios'; }
	);
	
	oTest.fnTest( 
		"Get id for a row with a hash",
		null,
		function () { return table.row('#Dai Rios').id(true) === '#Dai Rios'; }
	);
	
	oTest.fnTest( 
		"Get ids for a rows",
		null,
		function () {
			return JSON.stringify(table.rows([':eq(0)', ':eq(1)']).ids().toArray()) === '["Airi Satou","Angelica Ramos"]';
		}
	);
	
	oTest.fnTest( 
		"Get ids for a rows with a hash",
		null,
		function () {
			return JSON.stringify(table.rows([':eq(0)', ':eq(1)']).ids(true).toArray()) === '["#Airi Satou","#Angelica Ramos"]';
		}
	);
	
	
	oTest.fnComplete();
} );