File: rowId.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 (93 lines) | stat: -rw-r--r-- 2,338 bytes parent folder | download | duplicates (4)
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
describe('rowId option', function() {
	dt.libs({
		js: ['jquery', 'datatables'],
		css: ['datatables']
	});

	describe('Object-based data', function() {
		dt.html('empty');
		it('No ID if no rowId specified', function(done) {
			var table = $('#example').DataTable({
				ajax: '/base/test/data/data.txt',
				columns: [
					{ data: 'name' },
					{ data: 'position' },
					{ data: 'office' },
					{ data: 'age' },
					{ data: 'start_date' },
					{ data: 'salary' }
				],
				initComplete: function(settings, json) {
					expect(table.row(0).id()).toBe('undefined');
					expect($('#example tbody tr:eq(2)')[0].id).toBe('');
					done();
				}
			});
		});

		dt.html('empty');
		it('No ID if no rowId specified', function(done) {
			var table = $('#example').DataTable({
				ajax: '/base/test/data/data.txt',
				columns: [
					{ data: 'name' },
					{ data: 'position' },
					{ data: 'office' },
					{ data: 'age' },
					{ data: 'start_date' },
					{ data: 'salary' }
				],
				rowId: 'name',
				initComplete: function(settings, json) {
					expect(table.row(0).id()).toBe('Tiger Nixon');
					expect($('#example tbody tr:eq(2)')[0].id).toBe('Ashton Cox');
					done();
				}
			});
		});
	});

	describe('Non Object-based data', function() {
		dt.html('basic');
		it('When not set, no ID', function() {
			table = $('#example').DataTable();
			
			expect(table.row(0).id()).toBe('undefined');
			expect($('#example tbody tr:eq(2)')[0].id).toBe('');
		});		

		dt.html('basic');
		it('Adding when table initialised', function() {
			table = $('#example').DataTable({
				rowId: 0,
			});

			expect(table.row(0).id()).toBe('Tiger Nixon');
			expect($('#example tbody tr:eq(2)')[0].id).toBe('Ashton Cox');
		});

		dt.html('basic');
		it('Adding a row', function() {
			table = $('#example').DataTable({
				rowId: 0,
			});

			table.row.add(['Bruce Wayne', 'Superhero', 'Gotham', '34', '2018/04/04', '$1,000,000']).draw();

			expect(table.row(57).id()).toBe('Bruce Wayne');
			expect($('#example tbody tr:eq(6)')[0].id).toBe('Bruce Wayne');
		});
		
		dt.html('basic');
		it('Id removed when row deleted', function() {
			table = $('#example').DataTable({
				rowId: 3,
			});

			table.row(2).remove().draw();

			expect($('#example tbody tr:eq(2)')[0].id).toBe('41');
			expect($('#66').length).toBe(0);
		});	
	});
});