File: orderCellsTop.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 (160 lines) | stat: -rw-r--r-- 6,751 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
describe('orderCellsTop option', function() {
	dt.libs({
		js: ['jquery', 'datatables'],
		css: ['datatables']
	});
	describe('Check the defaults', function() {
		dt.html('basic');
		it('disabled by default- Using 1 row in header', function() {
			expect($.fn.dataTable.defaults.bSortCellsTop).toBe(false);
		});
		it('Disabled by default- Using 2 rows in header', function() {
			$('#example thead').append(
				'<tr><th>Name1</th><th>Position1</th><th>Office1</th><th>Age1</th><th>Start date1</th><th>Salary1</th></tr>'
			);
			let table = $('#example').DataTable();

			expect($('#example thead tr:eq(0) th:eq(0)').hasClass('sorting_asc')).toBe(false);
			expect($('#example thead tr:eq(1) th:eq(0)').hasClass('sorting_asc')).toBe(true);
			expect($(table.column(0).header()).text()).toBe('Name1');
		});

		dt.html('basic');
		it('Can be turned on- Using 2 rows in header', function() {
			$('#example thead').append(
				'<tr><th>Name1</th><th>Position1</th><th>Office1</th><th>Age1</th><th>Start date1</th><th>Salary1</th></tr>'
			);
			let table = $('#example').DataTable({
				orderCellsTop: true
			});

			expect($('#example thead tr:eq(0) th:eq(0)').hasClass('sorting_asc')).toBe(true);
			expect($('#example thead tr:eq(1) th:eq(0)').hasClass('sorting_asc')).toBe(false);
			expect($(table.column(0).header()).text()).toBe('Name');
		});
	});

	describe('Check when using 3 rows in header', function() {
		dt.html('basic');
		it('Disabled by default- Using 3 rows in header', function() {
			$('#example thead').append(
				'<tr><th>Name1</th><th>Position1</th><th>Office1</th><th>Age1</th><th>Start date1</th><th>Salary1</th></tr>'
			);
			$('#example thead').append(
				'<tr><th>Name2</th><th>Position2</th><th>Office2</th><th>Age2</th><th>Start date2</th><th>Salary2</th></tr>'
			);
			let table = $('#example').DataTable();

			expect($('#example thead tr:eq(0) th:eq(0)').hasClass('sorting_asc')).toBe(false);
			expect($('#example thead tr:eq(1) th:eq(0)').hasClass('sorting_asc')).toBe(false);
			expect($('#example thead tr:eq(2) th:eq(0)').hasClass('sorting_asc')).toBe(true);
			expect($(table.column(0).header()).text()).toBe('Name2');
		});

		dt.html('basic');
		it('Can be turned on- Using 3 rows in header', function() {
			$('#example thead').append(
				'<tr><th>Name1</th><th>Position1</th><th>Office1</th><th>Age1</th><th>Start date1</th><th>Salary1</th></tr>'
			);
			$('#example thead').append(
				'<tr><th>Name2</th><th>Position2</th><th>Office2</th><th>Age2</th><th>Start date2</th><th>Salary2</th></tr>'
			);
			let table = $('#example').DataTable({
				orderCellsTop: true
			});

			expect($('#example thead tr:eq(0) th:eq(0)').hasClass('sorting_asc')).toBe(true);
			expect($('#example thead tr:eq(1) th:eq(0)').hasClass('sorting_asc')).toBe(false);
			expect($('#example thead tr:eq(2) th:eq(0)').hasClass('sorting_asc')).toBe(false);
			expect($(table.column(0).header()).text()).toBe('Name');
		});
	});

	describe('Ignored when using ColSpan- 2 rows', function() {
		dt.html('basic');
		it('Disabled by default when using ColSpan- 2 rows', function() {
			$('#example thead').prepend('<tr><th colspan="3">HR Information</th><th colspan="3">Contact</th></tr>');
			let table = $('#example').DataTable();

			expect($('#example thead tr:eq(0) th:eq(0)').hasClass('sorting_asc')).toBe(false);
			expect($('#example thead tr:eq(1) th:eq(0)').hasClass('sorting_asc')).toBe(true);
			expect($(table.column(0).header()).text()).toBe('Name');
		});

		dt.html('basic');
		it('Enabled when using ColSpan- 2 rows', function() {
			$('#example thead').prepend('<tr><th colspan="3">HR Information</th><th colspan="3">Contact</th></tr>');
			let table = $('#example').DataTable({
				orderCellsTop: true
			});

			expect($('#example thead tr:eq(0) th:eq(0)').hasClass('sorting_asc')).toBe(false);
			expect($('#example thead tr:eq(1) th:eq(0)').hasClass('sorting_asc')).toBe(true);
			expect($(table.column(0).header()).text()).toBe('Name');
		});
	});

	describe('When using RowSpan', function() {
		dt.html('basic');
		it('Disabled by default when using RowSpan (first column, 2 rows)', function() {
			$('#example thead').prepend(
				'<tr><th rowspan="2">Name</th><th>Position</th><th>Office</th><th>Age</th><th>Start date</th><th>Salary</th></tr>'
			);
			$('#example thead tr:eq(1)').remove();
			$('#example thead').append(
				'<tr><th>Position1</th><th>Office1</th><th>Age1</th><th>Start date1</th><th>Salary1</th></tr>'
			);
			let table = $('#example').DataTable();

			expect($('#example thead tr:eq(0) th').hasClass('sorting_asc')).toBe(true);
			expect($(table.column(0).header()).text()).toBe('Name');
		});

		dt.html('basic');
		it('Enabled when using RowSpan (first column, 2 rows)', function() {
			$('#example thead').prepend(
				'<tr><th rowspan="2">Name</th><th>Position</th><th>Office</th><th>Age</th><th>Start date</th><th>Salary</th></tr>'
			);
			$('#example thead tr:eq(1)').remove();
			$('#example thead').append(
				'<tr><th>Position1</th><th>Office1</th><th>Age1</th><th>Start date1</th><th>Salary1</th></tr>'
			);
			let table = $('#example').DataTable({
				orderCellsTop: true
			});

			expect($('#example thead tr:eq(0) th').hasClass('sorting_asc')).toBe(true);
			expect($(table.column(0).header()).text()).toBe('Name');
		});

		dt.html('basic');
		it('Disabled by default when using RowSpan (second column, 2 rows)', function() {
			$('#example thead').prepend(
				'<tr><th>Name</th><th rowspan="2">Position</th><th>Office</th><th>Age</th><th>Start date</th><th>Salary</th></tr>'
			);
			$('#example thead tr:eq(1)').remove();
			$('#example thead').append('<tr><th>Name1</th><th>Office1</th><th>Age1</th><th>Start date1</th><th>Salary1</th></tr>');
			let table = $('#example').DataTable();

			expect($('#example thead tr:eq(0) th:eq(0)').hasClass('sorting_asc')).toBe(false);
			expect($('#example thead tr:eq(1) th:eq(0)').hasClass('sorting_asc')).toBe(true);
			expect($(table.column(0).header()).text()).toBe('Name1');
		});

		dt.html('basic');
		it('Enabled when using RowSpan (second column, 2 rows)', function() {
			$('#example thead').prepend(
				'<tr><th>Name</th><th rowspan="2">Position</th><th>Office</th><th>Age</th><th>Start date</th><th>Salary</th></tr>'
			);
			$('#example thead tr:eq(1)').remove();
			$('#example thead').append('<tr><th>Name1</th><th>Office1</th><th>Age1</th><th>Start date1</th><th>Salary1</th></tr>');
			let table = $('#example').DataTable({
				orderCellsTop: true
			});

			expect($('#example thead tr:eq(0) th:eq(0)').hasClass('sorting_asc')).toBe(true);
			expect($('#example thead tr:eq(1) th:eq(0)').hasClass('sorting_asc')).toBe(false);
			expect($(table.column(0).header()).text()).toBe('Name');
		});
	});
});