File: columns%28%29.data%28%29.js

package info (click to toggle)
datatables.js 1.10.13%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,232 kB
  • ctags: 1,329
  • sloc: xml: 10,249; php: 4,387; sh: 492; makefile: 21
file content (177 lines) | stat: -rw-r--r-- 5,438 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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// todo tests
// - Confirm it exists and is a function
// - Confirm it returns API instance
// - Select a single column and confirm that the data is returned for that column
// - Select two columns and confirm the data is returned for those two columns
// - Select all columns and confirm the data is returned for all columns
// - Test with both array based tables and object based tables
describe( "columns- columns().data()", function() {
	dt.libs( {
		js:  [ 'jquery', 'datatables' ],
		css: [ 'datatables' ]
	} );

	describe("Check the defaults", function () {
		dt.html( 'basic' );
		it("Exists and is a function", function () {
			var table = $('#example').DataTable();
			expect(typeof table.columns().data).toBe('function');
		});
		dt.html( 'basic' );
		it("Returns an API instance", function () {
			var table = $('#example').DataTable();
			expect(table.columns().data() instanceof $.fn.dataTable.Api).toBe(true);
		});
		dt.html( 'basic' );
		it("Data is returned for selected column only.", function () {
			var table = $('#example').DataTable();
			var testData = table.columns(0).data();

			expect(testData[0][0] == "Airi Satou" && testData[0][10] == "Charde Marshall").toBe(true);
		});
		dt.html( 'basic' );
		it("Data is returned for two columns.", function () {
			var table = $('#example').DataTable();
			var testData = table.columns([0,1]).data();
			console.log(testData);
			expect(
				testData[0][0] == "Airi Satou" &&
				testData[0][10] == "Charde Marshall" &&
				testData[1][0] == "Accountant" &&
				testData[1][9] == "Senior Javascript Developer").toBe(true);
		});
		dt.html( 'basic' );
		it("Data is returned for all columns.", function () {
			var table = $('#example').DataTable();
			var testData = table.columns().data();
			console.log(testData);
			expect(
				testData[0][0] == "Airi Satou" &&
				testData[1][1] == "Chief Executive Officer (CEO)" &&
				testData[2][2] == "San Francisco" &&
				testData[3][3] == "41" &&
				testData[4][4] == "2011/06/07" &&
				testData[5][5] == "$372,000").toBe(true);
		});

	});
	describe("Repeated with AJAX based table", function () {

				//AJAX
				dt.html( 'empty' );
				it("Exists and is a function", function (done) {
					table = $('#example').DataTable( {
						ajax: '/base/test/data/data.txt',
						deferRender: true,
						columns: [
							{ data: "name" },
							{ data: "position" },
							{ data: "office" },
							{ data: "extn" },
							{ data: "start_date" },
							{ data: "salary" }
						],
						initComplete: function ( settings, json ) {
							expect(typeof table.columns().data).toBe('function');
							done();
						}
					} );

				});
				dt.html( 'empty' );
				it("Returns an API instance", function (done) {
					table = $('#example').DataTable( {
						ajax: '/base/test/data/data.txt',
						deferRender: true,
						columns: [
							{ data: "name" },
							{ data: "position" },
							{ data: "office" },
							{ data: "extn" },
							{ data: "start_date" },
							{ data: "salary" }
						],
						initComplete: function ( settings, json ) {
							expect(table.columns().data() instanceof $.fn.dataTable.Api).toBe(true);
							done();
						}
					} );

				});
				dt.html( 'empty' );
				it("Data is returned for selected column only.", function (done) {
					table = $('#example').DataTable( {
						ajax: '/base/test/data/data.txt',
						deferRender: true,
						columns: [
							{ data: "name" },
							{ data: "position" },
							{ data: "office" },
							{ data: "extn" },
							{ data: "start_date" },
							{ data: "salary" }
						],
						initComplete: function ( settings, json ) {
							var testData = table.columns().data();
							console.log(testData);
							expect(testData[0][0] == "Airi Satou" && testData[0][10] == "Charde Marshall").toBe(true);
							done();
						}
					} );

				});
				dt.html( 'empty' );
				it("Data is returned for two columns.", function (done) {
					table = $('#example').DataTable( {
						ajax: '/base/test/data/data.txt',
						deferRender: true,
						columns: [
							{ data: "name" },
							{ data: "position" },
							{ data: "office" },
							{ data: "extn" },
							{ data: "start_date" },
							{ data: "salary" }
						],
						initComplete: function ( settings, json ) {
							var testData = table.columns([0,1]).data();
							expect(
								testData[0][0] == "Airi Satou" &&
								testData[0][10] == "Charde Marshall" &&
								testData[1][0] == "Accountant" &&
								testData[1][9] == "Senior Javascript Developer").toBe(true);
							done();
						}
					} );

				});
				dt.html( 'empty' );
				it("Data is returned for all columns.", function (done) {
					table = $('#example').DataTable( {
						ajax: '/base/test/data/data.txt',
						deferRender: true,
						columns: [
							{ data: "name" },
							{ data: "position" },
							{ data: "office" },
							{ data: "extn" },
							{ data: "start_date" },
							{ data: "salary" }
						],
						initComplete: function ( settings, json ) {
							var testData = table.columns().data();
							console.log(testData);
							expect(
								testData[0][0] == "Airi Satou" &&
								testData[1][1] == "Chief Executive Officer (CEO)" &&
								testData[2][2] == "San Francisco" &&
								testData[3][3] == "2558" &&
								testData[4][4] == "2011/06/07" &&
								testData[5][5] == "$372,000").toBe(true);
							done();
						}
					} );
				});
	});

});