Alphabatical order searching not working

Alphabatical order searching not working

sajilsajil Posts: 5Questions: 2Answers: 0

Hii,

This is my first question in datatables forum.Hope I will get the replay.I am trying to implement the alphabatical searcing with datatables according to the tutorial https://datatables.net/blog/2014-08-26,
But its not working,I am posting my codes here,Kindly do have a look,

// Jquery File

//Script for generating Datatable

    var oTable=$('#datatables').dataTable({


            "paging":   false,
            "searching": false,
            "info":      false,
    "scrollX":   true,
    "scrollCollapse": true,
            "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": global_base_url + "contact/list_view",


    "columnDefs": [

         {
            "render": function ( data, type, row ) {
               // alert(data);
                 return row[9];

            },
            "targets": 0,

        },
        {
            "render": function ( data, type, row ) {
               return row[10] ;                 
            },
            "targets": 1,

        },
        {
            "render": function ( data, type, row ) {
               return row[11] ;                 
            },
            "targets": 2,
             },                     
        {
            "render": function ( data, type, row ) {

                return '<img src="<?php echo base_url();?>asset/images/contacts/' + row[1] + '"   height="60" width="60"/>'+'&nbsp;'+row[2];                    

            },
            "targets": 3
        },
            {
            "render": function ( data, type, row ) {

             //  return '<input type="text" id="email" name="email" value='+row[3]+'>' ;  
              /*  return '<td>'+row[3]+'<td>' */
              return row[3];

            },
            "targets": 4,
             },
                 {
            "render": function ( data, type, row ) {
               return row[4] ;                  
            },
            "targets": 5,
             },
             {
            "render": function ( data, type, row ) {
               return row[5] ;                  
            },
            "targets": 6,
             },
                  {
            "render": function ( data, type, row ) {
               return row[6] ;                  
            },
            "targets": 7,
             },
                   {
            "render": function ( data, type, row ) {
               return row[7] ;                  
            },
            "targets": 8,
             },
                  {
            "render": function ( data, type, row ) {
               return row[8] ;                  
            },
            "targets": 9,
             }

    ],
        });

//codes for alphabatical order searching//

$(document).ready(function() {

var table = $('#datatables').DataTable();

var alphabet = $('<div class="alphabet"/>').append( 'Search: ' );


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

for ( var i=0 ; i<26 ; i++ ) {

    var letter = String.fromCharCode( 65 + i );

    $('<span/>')
        .data( 'letter', letter )
        .html( letter )
        .appendTo( alphabet );
}

alphabet.insertBefore( table.table().container() );

alphabet.on( 'click', 'span', function () {

alert('9');
    alphabet.find( '.active' ).removeClass( 'active' );
    $(this).addClass( 'active' );

    _alphabetSearch = $(this).data('letter');
    table.draw();
} );

});

var _alphabetSearch = '';

$.fn.dataTable.ext.search.push( function ( settings, searchData ) {
alert("a"); // I am not this alert,belive that there is something wrong over here
if ( ! _alphabetSearch ) {
return true;
}

if ( searchData[0].charAt(0) === _alphabetSearch ) {
    return true;
}

return false;

} );

//HTML

SYNC Email Customer Name Email ID Home Number Mobile Number Country ID# Title

Waiting for your replay.

This question has an accepted answers - jump to answer

Answers

  • sajilsajil Posts: 5Questions: 2Answers: 0

    is these searching possible in server side processing.?

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    You seem to have two scripts which both initialise the same table. Check your code against the example.

  • sajilsajil Posts: 5Questions: 2Answers: 0

    @tangerine. I have an error here
    if (searchData[0].charAt(0) === _alphabetSearch ) {
    alert('s');
    return true;
    }
    The alert is not working,could you tell what is wrong in this statement.? I am getting the value in _alphabetSearch.

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    Answer ✓

    Did you deal with my previous post?

  • sajilsajil Posts: 5Questions: 2Answers: 0

    @tangerine.It worked.There was some error in processing the json
    .I have changed it to :: searchData[3].charAt(1) === _alphabetSearch .

    thank you for your response.

This discussion has been closed.