1 |
// DATA_TEMPLATE: empty_table |
2 |
oTest.fnStart( "oSearch" ); |
3 |
|
4 |
$(document).ready( function () { |
5 |
/* Check the default */ |
6 |
var oTable = $('#example').dataTable( { |
7 |
"sAjaxSource": "../../../examples/ajax/sources/objects.txt", |
8 |
"aoColumns": [ |
9 |
{ "mData": "engine" }, |
10 |
{ "mData": "browser" }, |
11 |
{ "mData": "platform" }, |
12 |
{ "mData": "version" }, |
13 |
{ "mData": "grade" } |
14 |
] |
15 |
} ); |
16 |
var oSettings = oTable.fnSettings(); |
17 |
|
18 |
oTest.fnWaitTest( |
19 |
"Default values should be blank", |
20 |
null, |
21 |
function () { |
22 |
var bReturn = oSettings.oPreviousSearch.sSearch == "" && |
23 |
!oSettings.oPreviousSearch.bRegex; |
24 |
return bReturn; |
25 |
} |
26 |
); |
27 |
|
28 |
/* This test might be considered iffy since the full object isn't given, but it's reasonable to |
29 |
* expect DataTables to cope with this. It should just assumine regex false |
30 |
*/ |
31 |
oTest.fnWaitTest( |
32 |
"Search term only in object", |
33 |
function () { |
34 |
oSession.fnRestore(); |
35 |
oTable = $('#example').dataTable( { |
36 |
"sAjaxSource": "../../../examples/ajax/sources/objects.txt", |
37 |
"aoColumnDefs": [ |
38 |
{ "mData": "engine", "aTargets": [0] }, |
39 |
{ "mData": "browser", "aTargets": [1] }, |
40 |
{ "mData": "platform", "aTargets": [2] }, |
41 |
{ "mData": "version", "aTargets": [3] }, |
42 |
{ "mData": "grade", "aTargets": [4] } |
43 |
], |
44 |
"oSearch": { |
45 |
"sSearch": "Mozilla" |
46 |
} |
47 |
} ); |
48 |
}, |
49 |
function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Gecko"; } |
50 |
); |
51 |
|
52 |
oTest.fnWaitTest( |
53 |
"New search will kill old one", |
54 |
function () { |
55 |
oTable.fnFilter("Opera"); |
56 |
}, |
57 |
function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Presto"; } |
58 |
); |
59 |
|
60 |
oTest.fnWaitTest( |
61 |
"Search plain text term and escape regex true", |
62 |
function () { |
63 |
oSession.fnRestore(); |
64 |
$('#example').dataTable( { |
65 |
"sAjaxSource": "../../../examples/ajax/sources/objects.txt", |
66 |
"aoColumnDefs": [ |
67 |
{ "mData": "engine", "aTargets": [0] }, |
68 |
{ "mData": "browser", "aTargets": [1] }, |
69 |
{ "mData": "platform", "aTargets": [2] }, |
70 |
{ "mData": "version", "aTargets": [3] }, |
71 |
{ "mData": "grade", "aTargets": [4] } |
72 |
], |
73 |
"oSearch": { |
74 |
"sSearch": "DS", |
75 |
"bRegex": false |
76 |
} |
77 |
} ); |
78 |
}, |
79 |
function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Nintendo DS browser"; } |
80 |
); |
81 |
|
82 |
oTest.fnWaitTest( |
83 |
"Search plain text term and escape regex false", |
84 |
function () { |
85 |
oSession.fnRestore(); |
86 |
$('#example').dataTable( { |
87 |
"sAjaxSource": "../../../examples/ajax/sources/objects.txt", |
88 |
"aoColumnDefs": [ |
89 |
{ "mData": "engine", "aTargets": [0] }, |
90 |
{ "mData": "browser", "aTargets": [1] }, |
91 |
{ "mData": "platform", "aTargets": [2] }, |
92 |
{ "mData": "version", "aTargets": [3] }, |
93 |
{ "mData": "grade", "aTargets": [4] } |
94 |
], |
95 |
"oSearch": { |
96 |
"sSearch": "Opera", |
97 |
"bRegex": true |
98 |
} |
99 |
} ); |
100 |
}, |
101 |
function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Presto"; } |
102 |
); |
103 |
|
104 |
oTest.fnWaitTest( |
105 |
"Search regex text term and escape regex true", |
106 |
function () { |
107 |
oSession.fnRestore(); |
108 |
$('#example').dataTable( { |
109 |
"sAjaxSource": "../../../examples/ajax/sources/objects.txt", |
110 |
"aoColumnDefs": [ |
111 |
{ "mData": "engine", "aTargets": [0] }, |
112 |
{ "mData": "browser", "aTargets": [1] }, |
113 |
{ "mData": "platform", "aTargets": [2] }, |
114 |
{ "mData": "version", "aTargets": [3] }, |
115 |
{ "mData": "grade", "aTargets": [4] } |
116 |
], |
117 |
"oSearch": { |
118 |
"sSearch": "1.*", |
119 |
"bRegex": false |
120 |
} |
121 |
} ); |
122 |
}, |
123 |
function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "No matching records found"; } |
124 |
); |
125 |
|
126 |
oTest.fnWaitTest( |
127 |
"Search regex text term and escape regex false", |
128 |
function () { |
129 |
oSession.fnRestore(); |
130 |
$('#example').dataTable( { |
131 |
"sAjaxSource": "../../../examples/ajax/sources/objects.txt", |
132 |
"aoColumnDefs": [ |
133 |
{ "mData": "engine", "aTargets": [0] }, |
134 |
{ "mData": "browser", "aTargets": [1] }, |
135 |
{ "mData": "platform", "aTargets": [2] }, |
136 |
{ "mData": "version", "aTargets": [3] }, |
137 |
{ "mData": "grade", "aTargets": [4] } |
138 |
], |
139 |
"oSearch": { |
140 |
"sSearch": "1.*", |
141 |
"bRegex": true |
142 |
} |
143 |
} ); |
144 |
}, |
145 |
function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Gecko"; } |
146 |
); |
147 |
|
148 |
|
149 |
oTest.fnComplete(); |
150 |
} ); |