Individual column filtering server side - data column index is not correct

Individual column filtering server side - data column index is not correct

STKennethSTKenneth Posts: 7Questions: 3Answers: 0

I implement the individual column filtering as the following link - https://datatables.net/extensions/fixedcolumns/examples/styling/col_filter.html

table.columns().every( function (colIdx) {
var that = this;
$( 'input', $("#individualfilter th") ).on( 'keyup change', function (e) {
e.stopPropagation();
if ( that.search() !== this.value ) {
var data = that
.columns(this.accessKey)
.search( this.value )
;
that .draw();
}
} );
} );

but when I do filter in each column, it will filter previous column and filter function does not work in last column.

How do I debug it ?

Please see the below images.

https://goo.gl/photos/PMqXdsLVwMVJs4fe6

https://goo.gl/photos/DQhJkvqpMzWGFAq68

Answers

  • Tom (DataTables)Tom (DataTables) Posts: 139Questions: 0Answers: 26

    Hi STKenneth

    I believe when searching columns by index you have to refer to the column starting from 1 not 0.

    So if you wanted to select the last column from the image you posted you would use 4 not 3 as menu is a column as well.

    Thanks,

    Tom

  • STKennethSTKenneth Posts: 7Questions: 3Answers: 0

    Hello Tom,

    Thank you for your reply.

    In my second photo, I have tried to use 3 in columns and then do search but it does not work. How do I debug that? Is there any way to check that.

  • STKennethSTKenneth Posts: 7Questions: 3Answers: 0
    edited June 2016

    Hello Tom

    Please see the photo. Search function did not work for the last column
    https://goo.gl/photos/UMxakt5dp74BXRpg7

    My code

    var filterhtml ='';
    var ths = $('#table_id thead th');
    for(var i = 0, j= ths.length; i< j; i++)
    {
    var title = ths[i].textContent;
    if(title =="Menu")
    {
    filterhtml +='<th></th>';
    }
    else{
    filterhtml +='<th><input type="text" accessKey="'+(i+1)+'" data-index="'+(i+1)+'" placeholder="Search '+title+'" /></th>';
    }
    }

    var that = $('#table_id_wrapper thead').first();
    $("<thead id='individualfilter'><tr>"+filterhtml+"</tr></thead>").insertBefore( that);

    table.columns().every( function () {
    var that = this;
    $( 'input', $("#individualfilter th") ).on( 'keyup change', function () {
    if ( that.search() !== this.value ) {
    that
    .columns(this.accessKey)
    .search( this.value )
    .draw();
    }
    } );
    } );

  • STKennethSTKenneth Posts: 7Questions: 3Answers: 0

    Hello Tom,

    I think I already solve this issue after upgrading to 1.10.12.

    The previous version is 1.10.8.

    Thank you for your reply.

  • Tom (DataTables)Tom (DataTables) Posts: 139Questions: 0Answers: 26

    Hi Kenneth

    Thanks for the update, glad you got it working.

    Tom

This discussion has been closed.