Project

General

Profile

1
var tableOptions = {};
2
var table = null;
3

    
4
tableOptions  = {
5
     "order": [[ 0, "asc" ]],
6
    "dom": '<"top">rt<"bottom"><"clear">',
7
"paging": false
8
};
9

    
10
window.onload = function() {
11
    var outer = $('<div class="featured_top maincolumn2_top">');
12
    var alphabet = $('<div class="alphabet">').appendTo( outer );
13

    
14
    for ( var i=0 ; i<26 ; i++ ) {
15
        var letter = String.fromCharCode( 65 + i );
16
        $('<span class="alphaLetter">').data('letter', letter).html(letter).appendTo( alphabet );
17
    }
18

    
19
     $('<span class="clear active alphaLetter"/>').data( 'letter', '' ).html( 'ALL' ) .appendTo( alphabet );
20

    
21

    
22
    outer.insertBefore( '#listtbl');
23

    
24
    var table = jQuery('.data-table').DataTable(tableOptions);
25
    var _alphabetSearch;
26
    $.fn.dataTable.ext.search.push( function ( settings, searchData ) {
27
        if ( ! _alphabetSearch ) { // No search term - all results shown
28
            return true;
29
        }
30
        var word = searchData[0].replace(/\s+/g, '');
31
        if ( word.charAt(0) === _alphabetSearch ) {
32
            return true;
33
        }
34

    
35
        return false;
36
    } );
37

    
38

    
39

    
40
     alphabet.on( 'click', 'span', function () {
41
        alphabet.find( '.active' ).removeClass( 'active' );
42
        $(this).addClass( 'active' );
43

    
44
        _alphabetSearch = $(this).data('letter');
45
        table.draw();
46
    } );
47
};
(5-5/21)