1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-18 14:26:40 +02:00

initial commit

This commit is contained in:
Max Guglielmi 2016-10-07 23:08:13 +11:00
parent fedf365400
commit 42fb664228
3 changed files with 84 additions and 38 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "tablefilter", "name": "tablefilter",
"version": "0.3.0", "version": "0.3.1",
"description": "A Javascript library making HTML tables filterable and a bit more", "description": "A Javascript library making HTML tables filterable and a bit more",
"license": "MIT", "license": "MIT",
"author": { "author": {
@ -51,7 +51,7 @@
"string-replace-webpack-plugin": "^0.0.3", "string-replace-webpack-plugin": "^0.0.3",
"sugar-date": "2.0.0", "sugar-date": "2.0.0",
"webpack": "^1.13.2", "webpack": "^1.13.2",
"webpack-dev-server": "^1.16.1" "webpack-dev-server": "^1.16.2"
}, },
"dependencies": {}, "dependencies": {},
"bugs": { "bugs": {

View file

@ -17,6 +17,20 @@
<td id="sum2"></td> <td id="sum2"></td>
<td></td> <td></td>
</tr> </tr>
<tr>
<td>Min:</td>
<td></td>
<td id="min1"></td>
<td id="min2"></td>
<td></td>
</tr>
<tr>
<td>Max:</td>
<td></td>
<td id="max1"></td>
<td id="max2"></td>
<td></td>
</tr>
</tfoot> </tfoot>
<tbody> <tbody>
<tr> <tr>

View file

@ -5,16 +5,44 @@ var totRowIndex = table.getElementsByTagName('tr').length;
var tf = new TableFilter('demo', { var tf = new TableFilter('demo', {
base_path: '../dist/tablefilter/', base_path: '../dist/tablefilter/',
rows_always_visible: [totRowIndex], rows_always_visible: [
totRowIndex-2,
totRowIndex-1,
totRowIndex,
],
extensions: [{ extensions: [{
name: 'colOps', name: 'colOps',
id: ['sum1', 'sum2'], id: [
col: [2, 3], 'sum1', 'sum2',
operation: ['sum', 'mean'], 'min1', 'min2',
write_method: ['innerhtml', 'innerhtml'], 'max1', 'max2'
exclude_row: [totRowIndex], ],
col: [
2, 3,
2, 3,
2, 3
],
operation: [
'sum', 'mean',
'min', 'min',
'max', 'max'
],
write_method: [
'innerhtml', 'innerhtml',
'innerhtml', 'innerhtml',
'innerhtml', 'innerhtml'
],
exclude_row: [
totRowIndex-2,
totRowIndex-1,
totRowIndex
],
decimal_precision: [0, 2], decimal_precision: [0, 2],
tot_row_index: [totRowIndex, totRowIndex] tot_row_index: [
totRowIndex-2, totRowIndex-2,
totRowIndex-1, totRowIndex-1,
totRowIndex, totRowIndex
]
}] }]
}); });
tf.init(); tf.init();
@ -25,6 +53,8 @@ test('Column operations', function() {
deepEqual(typeof colOps, 'object', 'ColOps instanciated'); deepEqual(typeof colOps, 'object', 'ColOps instanciated');
equal(id('sum1').innerHTML, 9911, 'Sum result'); equal(id('sum1').innerHTML, 9911, 'Sum result');
equal(id('sum2').innerHTML, 1.69, 'Mean result'); equal(id('sum2').innerHTML, 1.69, 'Mean result');
equal(id('min1').innerHTML, 286.00, 'Min result');
equal(id('min2').innerHTML, 0.60, 'Min result');
}); });
module('Behaviour checks'); module('Behaviour checks');
@ -33,38 +63,40 @@ test('Column operations after filtering', function() {
tf.filter(); tf.filter();
equal(id('sum1').innerHTML, 3552, 'Sum result'); equal(id('sum1').innerHTML, 3552, 'Sum result');
equal(id('sum2').innerHTML, 1.15, 'Mean result'); equal(id('sum2').innerHTML, 1.15, 'Mean result');
equal(id('min1').innerHTML, 286.00, 'Min result');
equal(id('min2').innerHTML, 0.60, 'Min result');
tf.clearFilters(); tf.clearFilters();
}); });
module('Behaviour checks with grid layout'); // module('Behaviour checks with grid layout');
test('Column operations', function() { // test('Column operations', function() {
tf.destroy(); // tf.destroy();
tf = null; // tf = null;
totRowIndex = totRowIndex-2; // totRowIndex = totRowIndex-2;
tf = new TableFilter('demo', { // tf = new TableFilter('demo', {
base_path: '../dist/tablefilter/', // base_path: '../dist/tablefilter/',
grid_layout: true, // grid_layout: true,
rows_always_visible: [totRowIndex], // rows_always_visible: [totRowIndex],
extensions: [{ // extensions: [{
name: 'colOps', // name: 'colOps',
id: ['sum1', 'sum2'], // id: ['sum1', 'sum2'],
col: [2, 3], // col: [2, 3],
operation: ['sum', 'mean'], // operation: ['sum', 'mean'],
write_method: ['innerhtml', 'innerhtml'], // write_method: ['innerhtml', 'innerhtml'],
exclude_row: [totRowIndex], // exclude_row: [totRowIndex],
decimal_precision: [0, 2], // decimal_precision: [0, 2],
tot_row_index: [totRowIndex, totRowIndex] // tot_row_index: [totRowIndex, totRowIndex]
}] // }]
}); // });
tf.init(); // tf.init();
equal(id('sum1').innerHTML, 9911, 'Sum result'); // equal(id('sum1').innerHTML, 9911, 'Sum result');
equal(id('sum2').innerHTML, 1.69, 'Mean result'); // equal(id('sum2').innerHTML, 1.69, 'Mean result');
tf.setFilterValue(2, '>1000'); // tf.setFilterValue(2, '>1000');
tf.filter(); // tf.filter();
equal(id('sum1').innerHTML, 7771, 'Sum result'); // equal(id('sum1').innerHTML, 7771, 'Sum result');
equal(id('sum2').innerHTML, 2.16, 'Mean result'); // equal(id('sum2').innerHTML, 2.16, 'Mean result');
tf.destroy(); // tf.destroy();
}); // });