Search code examples
datatablesyadcf

Is possible to filter blank fields on multi_select?


I want to know if its possible to get the rows with empty fields on this columns. I have a fiddle to explain this.

At first column (Status) I have three values (ON, OFF, (EMPTY)). My problem is to get the rows with empty values (Same row as PR00000003, PR00000005) selecting empty value on the filter.

Thanks in advance.

Solution

  • Since there seems to be some sort of issue with yadcf/select2 and empty string for filtering I can suggest the following solutions:

    1) Use regex (see this jsfiddle) -

        var oTable = $('#example').DataTable();
    
        yadcf.init(oTable, [
            {
                column_number: 0,
                filter_type: 'multi_select',
                append_data_to_table_data: 'before',
                data: [ {value:'^$', label:'Empty' }], 
                filter_match_mode: 'regex',
                select_type: 'select2'
        }]);
    

    2) Use datatables HTML5 data-* attributes ,

    3) Use Chosen plugin (IMO Select2 fits datatables/yadcf better) instead of select2 see jsfiddle sample

            var oTable = $('#example').DataTable();
    
            yadcf.init(oTable, [
            {
                column_number: 0,
                filter_type: 'multi_select',
                append_data_to_table_data: 'before',
                data: [ {value:' ', label:'Empty' }], 
                filter_match_mode: 'exact',
                select_type: 'chosen'
            }]);
    

    always bet on yadcf