This is a migrated thread and some comments may be shown as answers.

Need help with a complex filter for datasource

3 Answers 18 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 25 Oct 2018, 01:28 PM

I have a listview that I need to create a filter for when a user clicks on a button.  The filter it needs to add is very complex and I am at a loss as to how to implement it.  The application I am building is taking an existing Access database application and converting it to MVC.  The filter they used in Access is below.  How can I convert this to work in the function at the bottom?  I have several filters like this to figure out so I greatly appreciate any help you can give me. 

"(((UM)='yes') AND ((FINDATE) Is Not Null) AND ((INVMANDATE) Is Null)) OR (((STKCLASS)='yes') AND ((FINDATE) Is Not Null) AND ((INVMANDATE) Is Null)) OR (((COMMCODE)='yes') AND ((FINDATE) Is Not Null) AND ((INVMANDATE) Is Null)) OR (((COMMONINV)='yes') AND ((FINDATE) Is Not Null) AND ((INVMANDATE) Is Null)) OR (((UM)<>'YES') AND ((STKCLASS)<>'YES') AND ((COMMCODE)<>'YES') AND ((COMMONINV)<>'YES') AND ((INVCTLDATE) Is Not Null) AND ((INVMANDATE) Is Null)) OR (((UM)<>'YES') AND ((STKCLASS)<>'YES') AND ((COMMCODE)<>'YES') AND ((COMMONINV)<>'YES') AND ((REQDATE) Is Not Null) AND ((INVMANDATE) Is Null))"

function filterListview() {
  var listView = $("#lvInvMan").data("kendoListView");
  listView.dataSource.filter({});
  var currentFilters = [], filter;
  var myfilter = {
     logic: "and",
     filters: currentFilters
  };
  listView.dataSource.filter(myfilter);
}

3 Answers, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 25 Oct 2018, 06:21 PM

I thought I had it figured out with the code below.  However, when I put a breakpoint in the controller the filter still shows null and none of the data is filtered.  Can you see anything wrong here?

function filterListview() {
        var listView = $("#lvInvMan").data("kendoListView");
        listView.dataSource.filter({});
 
        var currentFilters = [], filter;
 
        currentFilters = [
            {
                logic: "or",
                filters: [
                    {
                        login: "and",
                        filters: [
                            { field: "Um", operator: "eq", value: "YES" },
                            { field: "FinanceDate", operator: "isnotnull" },
                            { field: "InventoryManagementDate", operator: "isnull" },
                        ]
                    },
                    {
                        login: "and",
                        filters: [
                            { field: "StockClass", operator: "eq", value: "YES" },
                            { field: "FinanceDate", operator: "isnotnull" },
                            { field: "InventoryManagementDate", operator: "isnull" },
                        ]
                    },
                    {
                        login: "and",
                        filters: [
                            { field: "CommodityCode", operator: "eq", value: "YES" },
                            { field: "FinanceDate", operator: "isnotnull" },
                            { field: "InventoryManagementDate", operator: "isnull" },
                        ]
                    },
                    {
                        login: "and",
                        filters: [
                            { field: "CommonInv", operator: "eq", value: "YES" },
                            { field: "FinanceDate", operator: "isnotnull" },
                            { field: "InventoryManagementDate", operator: "isnull" },
                        ]
                    },
                    {
                        login: "and",
                        filters: [
                            { field: "Um", operator: "neq", value: "YES" },
                            { field: "StockClass", operator: "neq", value: "YES" },
                            { field: "CommodityCode", operator: "neq", value: "YES" },
                            { field: "CommonInv", operator: "neq", value: "YES" },
                            { field: "InventoryControlDate", operator: "isnotnull" },
                            { field: "InventoryManagementDate", operator: "isnull" },
                        ]
                    },
                    {
                        login: "and",
                        filters: [
                            { field: "Um", operator: "neq", value: "YES" },
                            { field: "StockClass", operator: "neq", value: "YES" },
                            { field: "CommodityCode", operator: "neq", value: "YES" },
                            { field: "CommonInv", operator: "neq", value: "YES" },
                            { field: "RequisitioningDate", operator: "isnotnull" },
                            { field: "InventoryManagementDate", operator: "isnull" },
                        ]
                    }
                ]
            }
        ];
 
        var myfilter = {
            logic: "and",
            filters: currentFilters
        };
 
        listView.dataSource.filter(myfilter);
    }

 

0
Viktor Tachev
Telerik team
answered on 29 Oct 2018, 11:33 AM
Hello Richard,

I have examined the code and it seems that there is a typo in the currentFilters array - the logic field for the nested filters is typed as login

Also, the filter() method is called with an empty object in the beginning of the filterListView function. This is not necessary as when filter() is called the previous filters that are applied will be ignored. Thus, you can call the method only once after the currentFilters array is created. 

Give the modifications a try and let me know how they work for you.


Regards,
Viktor Tachev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Richard
Top achievements
Rank 1
answered on 30 Oct 2018, 03:12 PM

You guys are awesome!  That typo was my problem.  No telling how long I looked at that code and never noticed it.

Thanks!!!

Tags
General Discussions
Asked by
Richard
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or