Need help with a complex filter for datasource

4 posts, 0 answers
  1. Richard
    Richard avatar
    31 posts
    Member since:
    Jan 2017

    Posted 25 Oct 2018 Link to this post

    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);
    }

  2. Richard
    Richard avatar
    31 posts
    Member since:
    Jan 2017

    Posted 25 Oct 2018 in reply to Richard Link to this post

    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);
        }

     

  3. Viktor Tachev
    Admin
    Viktor Tachev avatar
    2469 posts

    Posted 29 Oct 2018 Link to this post

    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.
  4. Richard
    Richard avatar
    31 posts
    Member since:
    Jan 2017

    Posted 30 Oct 2018 in reply to Viktor Tachev Link to this post

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

    Thanks!!!

Back to Top