File: row%28%29.data%28%29.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 (103 lines) | stat: -rw-r--r-- 2,851 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
describe('row - row().data()', function() {
	dt.libs({
		js: ['jquery', 'datatables'],
		css: ['datatables']
	});

	const newValue = 'New Value';
	const testRowData = ['Ashton Cox', 'Junior Technical Author', 'San Francisco', '66', '2009/01/12', '$86,000'];

	describe('Check the defaults', function() {
		dt.html('basic');
		it('Exists and is a function', function() {
			let table = $('#example').DataTable();
			expect(typeof table.row().data).toBe('function');
		});
	});

	describe('DOM tests', function() {
		dt.html('basic');
		it('GET - DOM Returns Array instance with all columns', function() {
			let table = $('#example').DataTable();
			let row = table.row().data();

			expect(row instanceof Array).toBe(true);
			expect(row.length).toBe(6);
		});

		dt.html('basic');
		it('GET - DOM Sourced Data - check row contents', function() {
			let table = $('#example').DataTable();
			expect(
				table
					.row(2)
					.data()
					.toString()
			).toBe(testRowData.toString());
		});

		dt.html('basic');
		it('SET - DOM Source Data - set one cell', function() {
			let table = $('#example').DataTable();
			let newRow = testRowData.slice(0); // clone the original array

			newRow[0] = newValue;
			table.row(2).data(newRow);

			expect($('#example tbody tr:eq(2) td:eq(0)').html()).toBe(newValue);
			expect(
				table
					.row(2)
					.data()
					.toString()
			).toBe(newRow.toString());
		});
	});

	describe('JSON tests', function() {
		dt.html('empty');
		it('GET - JSON Returns object containing all columns', function(done) {
			let table = $('#example').DataTable({
				ajax: '/base/test/data/data.txt',
				columns: dt.getTestColumns(),
				initComplete: function(settings, json) {
					let result = table.row(0).data();

					expect(typeof result).toBe('object');
					expect(Object.keys(result).length).toBe(table.columns().count());
					done();
				}
			});
		});

		dt.html('empty');
		it('GET - JSON Sourced Data - check row contents', function(done) {
			let table = $('#example').DataTable({
				ajax: '/base/test/data/data.txt',
				columns: dt.getTestColumns(),
				initComplete: function(settings, json) {
					expect(Object.values(table.row(2).data()).toString(), testRowData.toString());
					done();
				}
			});
		});

		dt.html('empty');
		it('SET - JSON Source Data - set one cell', function(done) {
			let table = $('#example').DataTable({
				ajax: '/base/test/data/data.txt',
				columns: dt.getTestColumns(),
				initComplete: function(settings, json) {
					// get the old row and modify it
					let newRow = table.row(2).data();
					newRow.name = newValue;
					table.row(2).data(newRow);

					expect($('#example tbody tr:eq(2) td:eq(0)').html()).toBe(newValue);
					expect(Object.values(table.row(2).data()).toString()).toBe(Object.values(newRow).toString());
					done();
				}
			});
		});
	});
});