File: lengthMenu.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 (112 lines) | stat: -rw-r--r-- 2,833 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
describe('lengthMenu Option', function() {
	dt.libs({
		js: ['jquery', 'datatables'],
		css: ['datatables']
	});

	function checkText(options, expected) {
		expect(options.length).toBe(expected.length);

		for (let i = 0; i < options.length; i++) {
			expect(options.eq(i).text()).toBe(expected[i]);
		}
	}

	function checkValue(options, expected) {
		expect(options.length).toBe(expected.length);

		for (let i = 0; i < options.length; i++) {
			expect(options.get(i).value).toBe(expected[i]);
		}
	}

	describe('Check the defaults', function() {
		dt.html('basic');
		it('Check default values', function() {
			$('#example').dataTable();

			let options = $('select option');
			checkText(options, ['10', '25', '50', '100']);
			checkValue(options, ['10', '25', '50', '100']);
		});

		dt.html('basic');
		it('Setting to non-default values', function() {
			$('#example').dataTable({
				lengthMenu: [15, 30, 45, 60]
			});

			let options = $('select option');
			checkText(options, ['15', '30', '45', '60']);
			checkValue(options, ['15', '30', '45', '60']);
		});

		dt.html('basic');
		it('Change length', function() {
			$('#example').dataTable({
				lengthMenu: [1, 10, 15]
			});

			let options = $('select option');
			checkText(options, ['1', '10', '15']);
			checkValue(options, ['1', '10', '15']);
		});

		dt.html('basic');
		it('Use different language strings', function() {
			$('#example').dataTable({
				lengthMenu: [[10, 25, 50, -1], [10, 25, 50, 'All']]
			});

			let options = $('select option');
			checkText(options, ['10', '25', '50', 'All']);
			checkValue(options, ['10', '25', '50', '-1']);
		});

		dt.html('basic');
		it('Large numbers are formatted for thousands', function() {
			$('#example').dataTable({
				lengthMenu: [[10, 25, 50, 10000, -1], [10, 25, 50, 10000, 'All']]
			});

			let options = $('select option');
			checkText(options, ['10', '25', '50', '10,000', 'All']);
			checkValue(options, ['10', '25', '50', '10000', '-1']);
		});
	});

	describe('Integration style tests', function() {
		dt.html('basic');
		it('Pagelength set to first size', function() {
			let table = $('#example').DataTable({
				lengthMenu: [15, 30, 45, 60]
			});

			expect(table.page.info().length).toBe(15);
		});

		dt.html('basic');
		it('Pagelength not set to first size if pageLength set', function() {
			let table = $('#example').DataTable({
				lengthMenu: [15, 30, 45, 60],
				pageLength: 12
			});

			expect(table.page.info().length).toBe(12);
		});

		dt.html('basic');
		it('Server-side processing', function(done) {
			let table = $('#example').DataTable({
				processing: true,
				serverSide: true,
				lengthMenu: [15, 30, 45, 60],
				ajax: dt.serverSide,
				initComplete: function(setting, json) {
					expect(table.page.info().length).toBe(15);
					done();
				}
			});
		});
	});
});