File: row%28%29.js

package info (click to toggle)
datatables.js 1.11.5%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 22,848 kB
  • sloc: javascript: 65,075; xml: 10,712; php: 4,741; sh: 544; makefile: 18
file content (133 lines) | stat: -rw-r--r-- 3,555 bytes parent folder | download | duplicates (3)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// todo tests - write the tests...

describe('rows - row()', function() {
	dt.libs({
		js: ['jquery', 'datatables'],
		css: ['datatables']
	});

	var table;
	var row;

	describe('Check the defaults', function() {
		dt.html('basic');
		it('Exists and is a function', function() {
			expect(typeof $('#example').DataTable().row).toBe('function');
		});

		it('Returns an API instance', function() {
			expect(
				$('#example')
					.DataTable()
					.row() instanceof $.fn.dataTable.Api
			).toBe(true);
		});
	});

	describe('Check the modifier parameter', function() {
		dt.html('basic');
		it('modifier - row index of 1, no data match', function() {
			table = $('#example').DataTable();

			// This will leave row index 4 in the display
			table.search('Airi Satou').draw();

			var d = table.row(1, { search: 'applied' }).data();
			expect(d).toBe(undefined);
		});

		it('modifier - row index of 0, no data match', function() {
			var d = table.row(0, { search: 'applied' }).data();
			expect(d).toBe(undefined);
		});

		it('modifier - row index of 4, data match', function() {
			var d = table.row(4, { search: 'applied' }).data();
			expect(d[0]).toBe('Airi Satou');
		});
	});

	describe('Check the modifier parameter - page', function() {
		dt.html('basic');
		it('no modifier - select row not on the page', function() {
			table = $('#example').DataTable();

			var d = table.row(19).node();
			expect(d.nodeName.toLowerCase()).toBe('tr');
		});

		it('modifier - select row not on the page', function() {
			var d = table.row(0, { page: 'current' }).node();
			expect(d).toBe(null);
		});
	});

	describe('Check the modifier parameter (jQuery)', function() {
		// GH #994
		dt.html('basic');
		it('Selecting a row as a jQuery instance', function() {
			table = $('#example').DataTable();

			table
				.clear()
				.row.add([0, 1, 2, 3, 4, 5])
				.draw();

			row = $('#example tbody tr');

			expect(table.row(row).node()).toBe(row[0]);
		});

		it('Delete the row from the table', function() {
			table.clear().draw();
			expect(table.rows().count()).toBe(0);
		});

		it('Selecting by save jQuery variable does not return the row', function() {
			expect(table.row(row).length).toBe(0);
			expect(table.row(row).node()).toBe(null);
		});

		dt.html('basic');
		it('Select top row and see if Airi COLIN', function() {
			table = $('#example').DataTable();
			var myrow = table.row(':eq(0)', { order: 'current' }).data();
			expect(myrow[0]).toBe('Airi Satou');
		});
	});

	describe('Check the rowSelector parameter', function() {
		// GH DataTables #1023
		dt.html('empty');
		it('Updating a row with an array of data where an id was originally present in the DOM will retain the id', function() {
			debugger;
			$('#example tbody').append(
				'<tr id="trident">' +
					'	<td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td>' +
					'</tr>' +
					'<tr id="nottrident">' +
					'	<td>7</td><td>8</td><td>9</td><td>10</td><td>11</td><td>12</td>' +
					'</tr>'
			);

			table = $('#example').DataTable();
			table
				.row('#trident')
				.data([0, 0, 0, 0, 0, 0])
				.remove()
				.draw();

			expect(table.row('#trident').node()).toBe(null);
		});

		dt.html('basic');
		it('Can use tr nodes to specify row', function() {
			table = $('#example').DataTable();
			expect(table.row($('tbody tr:eq(2)')).data()[0]).toBe('Ashton Cox');
		});
		it('Can use td nodes to specify row', function() {
			table = $('#example').DataTable();
			expect(table.row($('tbody tr:eq(2) td:eq(1)')).data()[0]).toBe('Ashton Cox');
		});
	});
});