2015-04-04 10:10:09 +02:00
|
|
|
|
2015-05-14 12:08:19 +02:00
|
|
|
var tag = function (elm, tag){ return elm.getElementsByTagName(tag); };
|
2015-04-04 10:10:09 +02:00
|
|
|
|
2015-05-14 12:08:19 +02:00
|
|
|
var tf = new TableFilter('demo', {
|
|
|
|
base_path: '../dist/tablefilter/',
|
2015-06-07 12:30:32 +02:00
|
|
|
extensions:[{
|
|
|
|
name: 'sort',
|
|
|
|
types:[
|
2015-05-14 12:08:19 +02:00
|
|
|
'String',
|
|
|
|
'enforceinteger',
|
|
|
|
'String',
|
|
|
|
'String',
|
|
|
|
'EU',
|
|
|
|
'US',
|
|
|
|
'String',
|
|
|
|
'dmydate',
|
|
|
|
'mdydate'
|
2015-06-07 12:30:32 +02:00
|
|
|
],
|
|
|
|
on_sort_loaded: function(tf, sort){
|
|
|
|
sort.addSortType('enforceinteger', customIntegerSorter);
|
|
|
|
startTest(tf, sort);
|
|
|
|
}
|
|
|
|
}]
|
2015-05-14 12:08:19 +02:00
|
|
|
});
|
2015-04-04 10:10:09 +02:00
|
|
|
|
2015-05-14 12:08:19 +02:00
|
|
|
//Custom sorter function
|
|
|
|
function customIntegerSorter(val){
|
|
|
|
var m = val.match(/\d+/);
|
|
|
|
return parseInt(m[0], 10);
|
|
|
|
}
|
2015-04-04 10:10:09 +02:00
|
|
|
|
2015-05-14 12:08:19 +02:00
|
|
|
tf.init();
|
2015-04-04 10:10:09 +02:00
|
|
|
|
2015-05-14 12:08:19 +02:00
|
|
|
function startTest(tf, sort){
|
|
|
|
module('Sanity checks');
|
|
|
|
test('Sort extension', function() {
|
|
|
|
notEqual(sort, null, 'Sort instanciated');
|
|
|
|
deepEqual(sort.sorted, false, 'Table not sorted');
|
2015-06-07 12:30:32 +02:00
|
|
|
deepEqual(sort.initialized, true, 'Sort initialized');
|
2015-05-14 12:08:19 +02:00
|
|
|
});
|
2015-04-04 10:10:09 +02:00
|
|
|
|
2015-05-14 12:08:19 +02:00
|
|
|
module('UI elements');
|
|
|
|
test('Sort UI elements', function() {
|
|
|
|
var th = tf.getHeaderElement(0),
|
|
|
|
indicator = tag(th, 'img'),
|
2015-05-24 11:16:09 +02:00
|
|
|
validRows = tf.getValidRows(true);
|
2015-04-04 10:10:09 +02:00
|
|
|
|
2015-05-14 12:08:19 +02:00
|
|
|
deepEqual(indicator.length, 1, 'Sort indicator in header element');
|
|
|
|
deepEqual(
|
2017-04-14 11:30:58 +02:00
|
|
|
(tf.dom().rows[validRows[0]].cells[1]).innerHTML,
|
2015-05-14 12:08:19 +02:00
|
|
|
'AUY78',
|
|
|
|
'First custom key cell text before sorting');
|
|
|
|
});
|
2015-04-04 10:10:09 +02:00
|
|
|
|
2015-05-14 12:08:19 +02:00
|
|
|
test('Sort behaviour', function() {
|
2015-06-07 12:30:32 +02:00
|
|
|
var validRows = tf.getValidRows(true);
|
2015-05-14 12:08:19 +02:00
|
|
|
sort.sortByColumnIndex(1);
|
2015-04-04 10:10:09 +02:00
|
|
|
|
2015-05-14 12:08:19 +02:00
|
|
|
deepEqual(sort.sorted, true, 'Table column sorted');
|
|
|
|
deepEqual(
|
2017-04-14 11:30:58 +02:00
|
|
|
(tf.dom().rows[validRows[0]].cells[1]).innerHTML,
|
2015-05-14 12:08:19 +02:00
|
|
|
'QT1',
|
|
|
|
'First custom key cell text after sorting');
|
|
|
|
});
|
2015-04-04 10:10:09 +02:00
|
|
|
|
2015-05-14 12:08:19 +02:00
|
|
|
module('Destroy and re-init');
|
|
|
|
test('Remove sort', function() {
|
|
|
|
sort.destroy();
|
|
|
|
var th = tf.getHeaderElement(0),
|
|
|
|
indicator = tag(th, 'img');
|
2015-06-07 12:30:32 +02:00
|
|
|
deepEqual(sort.initialized, false, 'Sort is removed');
|
2015-05-14 12:08:19 +02:00
|
|
|
deepEqual(indicator.length, 0, 'Sort indicator is removed');
|
|
|
|
});
|
|
|
|
}
|