File: orderCellsTop.js

package info (click to toggle)
datatables.js 1.10.19%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,348 kB
  • sloc: xml: 10,397; php: 4,448; sh: 521; makefile: 21
file content (100 lines) | stat: -rw-r--r-- 4,153 bytes parent folder | download
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
describe('orderCellsTop option', function() {
	dt.libs({
		js: ['jquery', 'datatables'],
		css: ['datatables']
	});
	//default only sorting on bottom, turned on top one, test with 3 rows and tests with rowspan
	describe('Check the defaults', function() {
		// dt.html( 'basic' );
		it('disabled by default- Using 1 row in header', function() {
			//could you also add a check for which cell `column().header()` returns in the orderCellsTop option please?
			$('#example').dataTable();
			expect($.fn.dataTable.defaults.bSortCellsTop).toBe(false);
		});
		dt.html('basic');
		it('Disabled by default- Using 2 rows in header', function() {
			$('#example thead').append(
				'<tr><th>Name</th><th>Position</th><th>Office</th><th>Age</th><th>Start date</th><th>Salary</th></tr>'
			);
			$('#example').dataTable();

			expect($('#example thead tr:eq(1) th:eq(0)').hasClass('sorting_asc')).toBe(true);
			expect($('#example thead tr:eq(0) th:eq(0)').hasClass('sorting_asc')).toBe(false);
		});
		dt.html('basic');
		it('Can be turned on- Using 2 rows in header', function() {
			$('#example thead').append(
				'<tr><th>Name</th><th>Position</th><th>Office</th><th>Age</th><th>Start date</th><th>Salary</th></tr>'
			);

			$('#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);
		});
	});

	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>Name</th><th>Position</th><th>Office</th><th>Age</th><th>Start date</th><th>Salary</th></tr>'
			);
			$('#example thead').append(
				'<tr><th>Name</th><th>Position</th><th>Office</th><th>Age</th><th>Start date</th><th>Salary</th></tr>'
			);
			$('#example').dataTable();

			expect($('#example thead tr:eq(2) 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(0) th:eq(0)').hasClass('sorting_asc')).toBe(false);
		});
		dt.html('basic');
		it('Can be turned on- Using 3 rows in header', function() {
			$('#example thead').append(
				'<tr><th>Name</th><th>Position</th><th>Office</th><th>Age</th><th>Start date</th><th>Salary</th></tr>'
			);
			$('#example thead').append(
				'<tr><th>Name</th><th>Position</th><th>Office</th><th>Age</th><th>Start date</th><th>Salary</th></tr>'
			);
			$('#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);
		});
	});

	describe('Test 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>');
			$('#example thead tr:eq(1)').remove();
			$('#example thead').append(
				'<tr><th>Name</th><th>Position</th><th>Office</th><th>Age</th><th>Start date</th><th>Salary</th></tr>'
			);
			$('#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);
		});
		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>');
			$('#example thead tr:eq(1)').remove();
			$('#example thead').append(
				'<tr><th>Name</th><th>Position</th><th>Office</th><th>Age</th><th>Start date</th><th>Salary</th></tr>'
			);
			$('#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);
		});
	});
});