mirror of
https://github.com/koalyptus/TableFilter.git
synced 2026-03-18 00:19:50 +01:00
Added filter with custom options logic + tests
This commit is contained in:
parent
bbd8997651
commit
c54e90162f
8 changed files with 250 additions and 57 deletions
79
test/test-custom-options.html
Normal file
79
test/test-custom-options.html
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>TableFilter filter with custom options tests</title>
|
||||
<link rel="stylesheet" href="libs/qunit/qunit.css">
|
||||
<script src="libs/qunit/qunit.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<table id="demo">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>From</th>
|
||||
<th>Destination</th>
|
||||
<th>Road Distance (km)</th>
|
||||
<th>By Air (hrs)</th>
|
||||
<th>By Rail (hrs)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><strong>Sydney</strong></td>
|
||||
<td>Adelaide</td>
|
||||
<td>1412</td>
|
||||
<td>1.4</td>
|
||||
<td>25.3</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Sydney</strong></td>
|
||||
<td>Brisbane</td>
|
||||
<td>982</td>
|
||||
<td>1.5</td>
|
||||
<td>16</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Sydney</strong></td>
|
||||
<td>Canberra</td>
|
||||
<td>286</td>
|
||||
<td>.6</td>
|
||||
<td>4.3</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Sydney</strong></td>
|
||||
<td>Melbourne</td>
|
||||
<td>872</td>
|
||||
<td>1.1</td>
|
||||
<td>10.5</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Adelaide</strong></td>
|
||||
<td>Perth</td>
|
||||
<td>2781</td>
|
||||
<td>3.1</td>
|
||||
<td>38</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Adelaide</strong></td>
|
||||
<td>Alice Springs</td>
|
||||
<td>1533</td>
|
||||
<td>2</td>
|
||||
<td>20.25</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Adelaide</strong></td>
|
||||
<td>Brisbane</td>
|
||||
<td>2045</td>
|
||||
<td>2.15</td>
|
||||
<td>40</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<script src="../dist/tablefilter/tablefilter.js"></script>
|
||||
<script src="test-custom-options.js"></script>
|
||||
|
||||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
</body>
|
||||
</html>
|
||||
100
test/test-custom-options.js
Normal file
100
test/test-custom-options.js
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
|
||||
(function(win, TableFilter){
|
||||
|
||||
var tf = new TableFilter('demo', {
|
||||
base_path: '../dist/tablefilter/',
|
||||
col_3: 'select',
|
||||
custom_options: {
|
||||
cols: [3],
|
||||
texts: [['0-0.5', '0.5-1', '1-2', '>2']],
|
||||
values: [['>0 && <=0.5', '>0.5 && <=1', '>1 && <=2', '>2']],
|
||||
sorts: [false]
|
||||
}
|
||||
});
|
||||
tf.init();
|
||||
|
||||
module('Sanity checks');
|
||||
test('Active columns', function() {
|
||||
deepEqual(tf instanceof TableFilter, true, 'TableFilter instanciated');
|
||||
deepEqual(
|
||||
tf.getFilterElement(3).nodeName, 'SELECT', 'Expected filter type');
|
||||
});
|
||||
|
||||
module('Behaviour');
|
||||
test('Filter column with custom filter', function() {
|
||||
var flt = tf.getFilterElement(3);
|
||||
flt.selectedIndex = flt.options.length-1;
|
||||
tf.filter();
|
||||
|
||||
deepEqual(
|
||||
tf.getFilteredData().length, 2, 'Expected nb of filtered rows');
|
||||
|
||||
tf.clearFilters();
|
||||
|
||||
deepEqual(
|
||||
tf.getFilteredData().length, 7, 'Expected nb of filtered rows');
|
||||
});
|
||||
|
||||
test('Paging: filter column with custom filter', function() {
|
||||
tf.destroy();
|
||||
tf = null;
|
||||
tf = new TableFilter('demo', {
|
||||
col_3: 'select',
|
||||
custom_options: {
|
||||
cols: [3],
|
||||
texts: [['0-0.5', '0.5-1', '1-2', '>2']],
|
||||
values: [['>0 && <=0.5', '>0.5 && <=1', '>1 && <=2', '>2']],
|
||||
sorts: [false]
|
||||
},
|
||||
paging: true,
|
||||
paging_length: 3
|
||||
});
|
||||
tf.init();
|
||||
|
||||
var flt = tf.getFilterElement(3);
|
||||
flt.selectedIndex = flt.options.length-1;
|
||||
tf.filter();
|
||||
|
||||
deepEqual(
|
||||
tf.getFilteredData().length, 2, 'Expected nb of filtered rows');
|
||||
|
||||
tf.clearFilters();
|
||||
|
||||
deepEqual(
|
||||
tf.getFilteredData().length, 7, 'Expected nb of filtered rows');
|
||||
|
||||
tf.destroy();
|
||||
tf = null;
|
||||
});
|
||||
|
||||
test('Grid layout: filter column with custom filter', function() {
|
||||
tf = new TableFilter('demo', {
|
||||
base_path: '../dist/tablefilter/',
|
||||
col_3: 'select',
|
||||
custom_options: {
|
||||
cols: [3],
|
||||
texts: [['0-0.5', '0.5-1', '1-2', '>2']],
|
||||
values: [['>0 && <=0.5', '>0.5 && <=1', '>1 && <=2', '>2']],
|
||||
sorts: [false]
|
||||
},
|
||||
grid_layout: true
|
||||
});
|
||||
tf.init();
|
||||
|
||||
var flt = tf.getFilterElement(3);
|
||||
flt.selectedIndex = flt.options.length-1;
|
||||
tf.filter();
|
||||
|
||||
deepEqual(
|
||||
tf.getFilteredData().length, 2, 'Expected nb of filtered rows');
|
||||
|
||||
tf.clearFilters();
|
||||
|
||||
deepEqual(
|
||||
tf.getFilteredData().length, 7, 'Expected nb of filtered rows');
|
||||
|
||||
tf.destroy();
|
||||
tf = null;
|
||||
});
|
||||
|
||||
})(window, TableFilter);
|
||||
Loading…
Add table
Add a link
Reference in a new issue