Problem with colvis and input filter

Problem with colvis and input filter

feederfeeder Posts: 8Questions: 3Answers: 0

Hi,

I have a strange issue with colvis and input filter...
I'm using input filter on each column with a keypress validation. It's working fine only for columns that are not hidden by default. If I display a new column, jquery never detect the input...

Someone can help me ?

$(document).ready(function() {

e = jQuery.Event("Keypress");
e.which = 13

$.fn.dataTable.moment( 'DD/MM/YYYY' );
$.extend( $.fn.dataTable.defaults, {
    "stateSave": false,
    "stateDuration": -1,
    "processing": true,
    "deferRender": true,
    "lengthChange": false,
    "paging": false,
    "language": {
        "url": "plugins/datatables/extensions/Localisation/French.json"
    },
    "columnDefs": [
        {
            "targets": [0,1,2,3],
            "visible": false,
            "searchable": false
        }
    ],
    dom: 'Bfrtip',
    buttons:
        [
            {
                extend: 'colvis',
                className: 'btn btn btn-default buttons-colvis',
                text: 'Affichage',
                columns: ':not(.noVis)'
            }

        ]
} );

/*********************Add filters**************/
$('table tfoot th').each( function () { 
    var id = $(this).closest('table').attr('id');
    var title = $(this).text();
    var indexColumn = $(this).index();
    $(this).html( '<input id="'+indexColumn+'-'+id+'" class="'+id+' filtertable" type="text" placeholder="'+title+'" data-search="'+indexColumn+'" />' );
});
/*********************Init datatable**************/
var table = $('#myTable').DataTable();
/*********************End init **************/

/**********************Filter function******************** */
$('.filtertable').on('keypress', function(e) {
    if(e.which == 13){
        var paramSearch =  $(this).data( "search" )
        var col = $(this).closest('th').data( "index" );
        var inputValue= this.value;
        console.log(col);
        console.log(inputValue);
        table
            .columns( col )
            .search( this.value, true, false, true )
            .draw();

    }
});
/************************End filter function**************** */

} );

Answers

  • feederfeeder Posts: 8Questions: 3Answers: 0

    Nobody has any idea ?

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @feeder ,

    There's a lot going on there. We're happy to take a look, but it would help, as per the forum rules, if you could link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.