We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Filter for NULL and empty values

I am looking for a way to use filterbar and filter also NULL end empty values. There is EnableComplexBlankFilter() Method that 'It sets the value that indicates to perform the filter operation with empty, null and undefined values.' but I cant find any information about how it should be used?

1 Reply

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team July 6, 2017 03:47 PM UTC

Hi Customer, 

Thanks for contacting syncfusion support. 

Filtering  “NULL and empty values”  by using EnableComplexBlankFilter() method only supports for Excel type of filtering. But we have achieved your requirement filtering null and empty values using “ filterBarTemplate” property.  In the “read” event of the Template column,  we have get the filtered value and stored it in filterObject. After that we have pushed the filterObject into the this.model.filterSettings.filterColumns property and updated the Grid with refreshContent() method. 

Please refer to the code example:- 

<script type="text/javascript"> 
        $(function () { 
              $("#Grid").ejGrid({ 
                dataSource:ej.DataManager(shipDetails), 
                allowPaging :true, 
                           columns: [ 
                          { 
                            field: "ShipName", width: 100, filterBarTemplate: { 
                                create: function (args) { 
                                    return "<input>" 
                                }, 
                                write: function (args) { 
                                    var data = ej.DataManager(shipDetails).executeLocal(new ej.Query().select("ShipName")); 
                                    args.element.ejAutocomplete({ width: "100%", dataSource: data, enableDistinct: true, focusOut:       ej.proxy(args.column.filterBarTemplate.read, this, args) }); 
                                }, 
                                read: function (args) { 
                                          var filterObject = { 
                                             value:  args.element.val(), 
                                             field:  "ShipName", 
                                             operator: (args.element.val() == ''|| args.element.val() == null)? "equal" : "startswith", 
                                             type: "string", 
                                             predicate: "and", 
                                          }; 
                                    this.model.filterSettings.filteredColumns.push(filterObject); 
                                   this.refreshContent(); 
                                }, 
                              }, 
                            }, 
                           { field: "ShipCity", headerText: "Ship City", width: 80 } 
 
                       ], 
              }); 
 
        }); 
       var shipDetails = [ 
          { ShipName: null, ShipCity: 'Brazil' }, 
          { ShipName: 'Ale', ShipCity: 'USA' }, 
          { ShipName: 'Ricardo Adocicados', ShipCity: 'Brazil' } 
       ]; 
   </script> 


Please refer to the sample and API link :-  http://jsplayground.syncfusion.com/aoeqapkf 


Please get back to us if you need any further assistance. 

Regards, 

Farveen sulthana T 


Loader.
Live Chat Icon For mobile
Up arrow icon