File: columns_searchable.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 (68 lines) | stat: -rw-r--r-- 2,511 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
describe('columns.searchable option', function() {
	dt.libs({
		js: ['jquery', 'datatables'],
		css: ['datatables']
	});

	describe('Check the defaults', function() {
		function isSearchableCorrect(expected) {
			for (i = 0; i < 6; i++) {
				if (expected[i] !== table.settings()[0].aoColumns[i].bSearchable) {
					return false;
				}
			}

			return true;
		}

		dt.html('basic');
		it('Columns are searchable by default', function() {
			table = $('#example').DataTable();
			table.search('Airi Satou').draw();
			expect($('#example tbody tr:eq(0) td:eq(0)').text()).toBe('Airi Satou');
			expect(isSearchableCorrect([true, true, true, true, true, true])).toBe(true);
		});

		dt.html('basic');
		it('Disabling sorting on a column removes it from the global filter', function() {
			table = $('#example').DataTable({
				columns: [null, { searchable: false }, null, null, null, null]
			});
			table.search('Accountant').draw();
			expect($('#example tbody tr:eq(0) td:eq(0)').text()).toBe('No matching records found');
			expect(isSearchableCorrect([true, false, true, true, true, true])).toBe(true);
		});
		it('Disabled on one column has no effect on other columns', function() {
			table.search('Airi Satou').draw();
			expect($('#example tbody tr:eq(0) td:eq(0)').text()).toBe('Airi Satou');
		});

		dt.html('basic');
		it('Disble searching on multiple columns', function() {
			table = $('#example').DataTable({
				columns: [null, { searchable: false }, { searchable: false }, null, null, null]
			});
			table.search('Accountant').draw();
			expect($('#example tbody tr:eq(0) td:eq(0)').text()).toBe('No matching records found');
			expect(isSearchableCorrect([true, false, false, true, true, true])).toBe(true);
		});
		it('Filter on second column disabled', function() {
			table.search('tokyo').draw();
			expect($('#example tbody tr:eq(0) td:eq(0)').text()).toBe('No matching records found');
		});
		it('Disabled on one column has no effect on other columns', function() {
			table.search('Airi Satou').draw();
			expect($('#example tbody tr:eq(0) td:eq(0)').text()).toBe('Airi Satou');
		});

		dt.html('basic');
		it('Disble all colimns using columnDefs', function() {
			table = $('#example').DataTable({
				columnDefs: [{ searchable: false, targets: '_all' }]
			});
			table.search('a').draw();
			expect($('#example tbody tr:eq(0) td:eq(0)').text()).toBe('No matching records found');
			expect(isSearchableCorrect([false, false, false, false, false, false])).toBe(true);
		});
	});
});