How do I filter a grid?

Posted by Bert Binnenmarsch on 15-May-2017 05:15

I found the following code in several places with minor differences:

onShow: function($scope, customData) {
    this.scope = $scope;

    var filter = {
      logic:'and',
      filters: [
          { field: 'somefieldname', operator: 'eq', value: 2}
               ]
    }; 
    this.scope.grid.options.autoBind = false;
    this.scope._$ds.filter(filter);
},

Whatever I try, nothing is working.

All Replies

Posted by Anil Kumar on 15-May-2017 10:24

Hi Bert,
 
When using a view which was created using ‘Blank’ view option in the ‘Add View’ wizard in KUIB designer, we need to append/add specific ‘View Data Source’ name as part of the filter criteria. However, when we use a view which was created using other pre-defined templates (Data Grid, Data Grid Form, Data Grid Separate Form) then inclusion of this data source in filter criteria is optional as the view is always bound to single data source.
 
I tried following scenarios and it worked fine in both views/screens which was created using ‘blank’ view option and ‘Data Grid’ view option(s).
 
‘Blank’ view code snippet: Here ‘myVDS’ is the name of my view data source and ‘CustNum’ is the column/field name.
 
                onShow: function ($scope, customData) {
                                this.scope = $scope;
 
                                var filter = {
                                                logic: 'and',
                                                filters: [
                                                                {
                                                                                field: 'CustNum',
                                                                                operator: 'eq',
                                                                                value: 2
                                                                }
                                                                   ]
                                };
                                this.scope._$ds['myVDS'].filter(filter);
                },
 
 
 
 
‘Data Grid’ view code snippet: Here ‘CustNum’ is the column/field name.
 
onShow: function ($scope, customData) {
                this.scope = $scope;
 
                var filter = {
                                logic: 'and',
                                filters: [
                                                {
                                                                field: 'CustNum',
                                                                operator: 'eq',
                                                                value: 2
                                                }
                                                   ]
                };
                this.scope._$ds.filter(filter);
}
 
 
Hope this helps.
 
Thanks and Regards,
Anil Kumar.
 

Posted by Bert Binnenmarsch on 16-May-2017 03:49

Filtering is working now for a DATA GRID too after removing debug code.

This thread is closed