Show / Hide bFiltered checkbox toggle

Show / Hide bFiltered checkbox toggle

lgkelgke Posts: 2Questions: 1Answers: 0

Hello,

How can i change the bFiltered:true option?

I want to show / hide the column filter dynamically!

Answers

  • lgkelgke Posts: 2Questions: 1Answers: 0

    I solved the problem,

    • re init the table, change the filter options.
    • hide the column input fields when switching back to no filter. (think this is a bug)

      function createOverviewTable(withFilter) {
          if (withFilter === true) {
              $('#contactOverviewTable').dataTable
             ({
                 "bPaginate": false,
                 "bInfo": false,
                 "bIgnoreEmpty": true,
                 "bFiltered": true,
                 "bFilter": true,
                 "bjQueryUI": false,
                 "bDestroy": true,
                 "processing": true,
                 "columns": [
                       { "data": 'aanspreekTitel', "name": 'aanspreekTitel' },
                       { "data": 'naam', "name": 'naam' },
                       { "data": 'functieTitel', "name": 'functieTitel' }
                 ],
                 "fnRowCallback": function (nRow, aData, iDisplayIndex) {
                     $(nRow).attr("id", aData.contactpuntId);
                     return nRow;
                 }
                 }
             });
      
              $('#contactOverviewTable').dataTable().columnFilter(
              {
                  sPlaceHolder: 'head:before',
                  aoColumns: [
                                 {
                                     type: "text",
                                     bSearchable: true
                                 },
                                 {
                                     type: "text",
                                     bSearchable: true
                                 },
                                 {
                                     type: "text",
                                     bSearchable: true
                                 }
                  ]
              });
      
              $('div.dataTables_filter input').attr('placeholder', '@Resources.Labels.Search');
          }
          else {
              $('#contactOverviewTable').dataTable
             ({
                 "bPaginate": false,
                 "bInfo": false,
                 "bIgnoreEmpty": true,
                 "bFiltered": false,
                 "bFilter": false,
                 "bjQueryUI": false,
                 "bDestroy": true,
                 "processing": true,
                 "columns": [
                       { "data": 'aanspreekTitel', "name": 'aanspreekTitel' },
                       { "data": 'naam', "name": 'naam' },
                       { "data": 'functieTitel', "name": 'functieTitel' }
                 ],
                 "fnRowCallback": function (nRow, aData, iDisplayIndex) {
                     $(nRow).attr("id", aData.contactpuntId);
                     return nRow;
                 }
                 }
             });
      
              $('.filter_column.filter_text input.text_filter').replaceWith(function () {
                  return '<span class=' + this.className + '>' + this.defaultValue + '</span>'
              })
          }
      }
      
This discussion has been closed.