File: deferRender.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 (154 lines) | stat: -rw-r--r-- 3,897 bytes parent folder | download | duplicates (2)
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
describe('deferRender option', function() {
	let table;
	dt.libs({
		js: ['jquery', 'datatables'],
		css: ['datatables']
	});

	describe('Check Default', function() {
		it('Is disabled by default', function() {
			expect($.fn.dataTable.defaults.bDeferRender).toBe(false);
		});
	});

	function checkNodes(cells, rows) {
		expect(
			table
				.cells()
				.nodes()
				.count()
		).toBe(cells);
		expect(
			table
				.rows()
				.nodes()
				.count()
		).toBe(rows);
	}

	describe('Functional tests - disabled', function() {
		dt.html('empty');
		it('All nodes present after initialisation', function(done) {
			table = $('#example').DataTable({
				ajax: '/base/test/data/data.txt',
				deferRender: false,
				columns: [
					{ data: 'name' },
					{ data: 'position' },
					{ data: 'office' },
					{ data: 'age' },
					{ data: 'start_date' },
					{ data: 'salary' }
				],
				initComplete: function(settings, json) {
					checkNodes(342, 57);
					done();
				}
			});
		});
	});

	describe('Functional tests - enabled', function() {
		dt.html('empty');
		it('Only displayed nodes are created', function(done) {
			table = $('#example').DataTable({
				ajax: '/base/test/data/data.txt',
				deferRender: true,
				columns: [
					{ data: 'name' },
					{ data: 'position' },
					{ data: 'office' },
					{ data: 'age' },
					{ data: 'start_date' },
					{ data: 'salary' }
				],
				initComplete: function(settings, json) {
					checkNodes(60, 10);
					done();
				}
			});
		});
		it('On next page 10 more rows are created', function() {
			table.page('next').draw(false);
			checkNodes(120, 20);
		});
		it('Jumping back to first page, no more rows are created', function() {
			table.page('previous').draw(false);
			checkNodes(120, 20);
		});
		it('Jumping to last page will not render all rows', function() {
			table.page('last').draw(false);
			checkNodes(162, 27);
		});
		it("Jumping back to first page again doesn't create more", function() {
			table.page('first').draw(false);
			checkNodes(162, 27);
		});
		it('Filtering will create only those required', function() {
			table.search('m').draw();
			checkNodes(186, 31);
		});
		it('Ordering will only create those required', function() {
			table.order([0, 'desc']).draw();
			checkNodes(222, 37);
		});

		dt.html('empty');
		it('Can modify data of undrawn rows', function(done) {
			table = $('#example').DataTable({
				ajax: '/base/test/data/data.txt',
				deferRender: true,
				columns: [
					{ data: 'name' },
					{ data: 'position' },
					{ data: 'office' },
					{ data: 'age' },
					{ data: 'start_date' },
					{ data: 'salary' }
				],
				initComplete: function(settings, json) {
					expect(table.row(1).data().name).toEqual('Garrett Winters');
					done();
				}
			});
		});
		it('... and can change the value', function() {
			table
				.row(1)
				.data(dt.makePersonObject('a unit test'))
				.draw();
			expect($('tbody tr:eq(0) td:eq(0)').text()).toBe('a unit test');
			expect(table.row(1).data().name).toEqual('a unit test');
			expect(table.cell(1, 0).data()).toBe('a unit test');
		});

		dt.html('empty');
		it('Can modify data of undrawn cells', function(done) {
			table = $('#example').DataTable({
				ajax: '/base/test/data/data.txt',
				deferRender: true,
				columns: [
					{ data: 'name' },
					{ data: 'position' },
					{ data: 'office' },
					{ data: 'age' },
					{ data: 'start_date' },
					{ data: 'salary' }
				],
				initComplete: function(settings, json) {
					expect(table.row(1).data().name).toEqual('Garrett Winters');
					done();
				}
			});
		});
		it('... and can change the value', function() {
			table
				.cell(1, 0)
				.data('a unit test')
				.draw();
			expect($('tbody tr:eq(0) td:eq(0)').text()).toBe('a unit test');
			expect(table.row(1).data().name).toEqual('a unit test');
			expect(table.cell(1, 0).data()).toBe('a unit test');
		});
	});
});