Search code examples
jquerydatatableyadcf

YADCF, column visibility doesn't work properly with filter_container_id


I've a little issue with Datatables, YADCF and Button Colvis : I can't use in the same table the property visible:false, a filter_container_id and yadcf. The yadcf plugin crash and not display anything. This is an cleaned-up version of my datatable initialisation :

datatable = $('#Datatable').DataTable({
    serverSide:true,
    processing:true,
    ajax: {
        url: '/app/object/liste',
        type: "POST"
    },
    columns: [
        {data:"pc_id", width:"90px"},
        {data:"pc_statut", visible:false, width:"90px"},
        {data:"reference_dossier", width:"90px"}],
    buttons: [{
        extend: 'colvis',
        text: 'Colonnes',
        collectionLayout: 'fixed three-column',
        columns: ':gt(0)'
    }],
    initComplete:function(a, b){
        new $.fn.dataTable.FixedColumns(datatable, {
            leftColumns: 1
        });

        var clonedTable = document.querySelectorAll('.DTFC_Cloned');
        for (var i = 0; i < clonedTable.length; i++){
            clonedTable[i].id = 'DTFC_Cloned';
        }
        $('#DTFC_Cloned thead tr:eq(1) th:last-child').append(
            '<span id="fixed_col_filter_container"></span>'
        );

        yadcf.init(
            datatable,
            [
                {
                    column_number:1,
                    filter_container_id:"fixed_col_filter_container",
                    filter_type:"text",
                    filter_delay:"500"
                },{
                    column_number:2,
                    filter_container_id:"pc-pc_statut-2",
                    filter_type:"text",
                    filter_delay:"500"
                },{
                    column_number:3,
                    filter_container_id:"pc-reference_dossier-2",
                    filter_type:"text",
                    filter_delay:"500"
                }
            ],
            {language: tabLanguage}
        );
    }
});

Solution

  • I added a fix to yadcf and fixed your code as well,

    Grab the latest 0.9.0.beta.23 and note that column_number values are zero based (first column should have column_number: 0 and so on)

    See it working here