jQWidgets Forums

jQuery UI Widgets Forums TreeGrid jqxTreeGrid filter condition filter_or_operator NOT working

This topic contains 4 replies, has 2 voices, and was last updated by  rao 9 years, 4 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author

  • rao
    Participant

    Hi JqWidget Team,
    I am using jqxTreeGrid.
    I have a requirement of filters combination.
    Here is my case : At the top of the table there will be search implementation.
    Once i make the search it gives me matching records(on datafieldX) in the TreeGrid.
    And i have 2 toggle buttons (datafield1, datafield2) to filter data further.
    Here i have a requirement of showing the records from search Result, either if datafiled1 matches or datafield2 matches.
    Assume datafiled1 is Designation (my criteria is ‘Manager’) and datafiled2 is Dept (my criteria is “Sales”)
    Finally : 1) i will make text based “search”, say location as “London” (assume i got 50 resulted rows out of 100.) — result 50 rows
    2) I will click on ‘Show managers’ button (there are 5 out of 2 working in SALES dept) — result is 5 rows
    3) I will click on ‘show Sales People’ button (there are 20 sales ppl out of 50 from the results of #1) — result is : 23
    NOTE : There are 20 sales ppl, out of that there are 2 managers; And rest 3 are ‘Managers’ working in different departments, London based.
    i have implemented something like below
    var filterGroup = new $.jqx.filter();
    var filter_or_operator = 1; //OR condition
    var filterValue = true;
    var filterCondition = ‘equal’;
    var filter = filterGroup.createfilter(‘booleanfilter’, filterValue, filterCondition);
    filterGroup.addfilter(filter_or_operator, filter);
    the same filterGroup i used for adding both filters (managers, sales)
    althogh my filter_or_operatior is assigned to 1, i am not seeing the expected count of 23, but ONLY 2, which is INTERSECT of condition.
    Can i get some help here please ?

    Regards,
    Rao.


    Peter Stoev
    Keymaster

    Hi Rao,

    The provided information in your topic is not sufficient for testing your scenario. Please, prepare https://www.jseditor.io/ example and share what you try to do.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    rao
    Participant

    Hi Peter,
    Thanks for the response.
    I have created an example
    https://www.jseditor.io/?key=filters-with-or-condition
    Please take a look at it.

    in the example i have created, there are 2 buttons, below the table.
    One with label “Sales Representatives” other one with “USA Based Employees”

    My intention is to get the appropriate list of
    1) first button click should show me list of records, whose Title Contains “Representative” (in the example there are 6 records)
    2) second button click should show me list of records, whose Country contains “USA” (in example there are 5 records)
    3) after clicking both buttons (assume in my application they are check boxes) ; i should see all the records, whether COUNTRY is “USA” or Title has “Representative” (so from the example data, i expect 8 records. means, only ‘Steven, Buchan’ doesn’t qualify any conditions applied; rest all are matching EITHER country OR title)

    Please let me know if any clarity is required.

    Regards,
    Rao.


    Peter Stoev
    Keymaster

    Hi Rao,

    The TreeGrid in the provided example is not created correctly. You are missing parts of the initialization code.

    Here’s the updated code:

    $(document).ready(function () {
    var employees = [{ "EmployeeID": 1, "FirstName": "Nancy", "LastName": "Davolio", "ReportsTo": 2, "Country": "USA", "Title": "Sales Representative", "HireDate": "1992-05-01 00:00:00", "BirthDate": "1948-12-08 00:00:00", "City": "Seattle", "Address": "507 - 20th Ave. E.Apt. 2A" }, { "EmployeeID": 2, "FirstName": "Andrew", "LastName": "Fuller", "ReportsTo": null, "Country": "USA", "Title": "Vice President, Sales", "HireDate": "1992-08-14 00:00:00", "BirthDate": "1952-02-19 00:00:00", "City": "Tacoma", "Address": "908 W. Capital Way" }, { "EmployeeID": 3, "FirstName": "Janet", "LastName": "Leverling", "ReportsTo": 2, "Country": "USA", "Title": "Sales Representative", "HireDate": "1992-04-01 00:00:00", "BirthDate": "1963-08-30 00:00:00", "City": "Kirkland", "Address": "722 Moss Bay Blvd." }, { "EmployeeID": 4, "FirstName": "Margaret", "LastName": "Peacock", "ReportsTo": 2, "Country": "USA", "Title": "Sales Representative", "HireDate": "1993-05-03 00:00:00", "BirthDate": "1937-09-19 00:00:00", "City": "Redmond", "Address": "4110 Old Redmond Rd." }, { "EmployeeID": 5, "FirstName": "Steven", "LastName": "Buchanan", "ReportsTo": 2, "Country": "UK", "Title": "Sales Manager", "HireDate": "1993-10-17 00:00:00", "BirthDate": "1955-03-04 00:00:00", "City": "London", "Address": "14 Garrett Hill" }, { "EmployeeID": 6, "FirstName": "Michael", "LastName": "Suyama", "ReportsTo": 5, "Country": "UK", "Title": "Sales Representative", "HireDate": "1993-10-17 00:00:00", "BirthDate": "1963-07-02 00:00:00", "City": "London", "Address": "Coventry House Miner Rd." }, { "EmployeeID": 7, "FirstName": "Robert", "LastName": "King", "ReportsTo": 5, "Country": "UK", "Title": "Sales Representative", "HireDate": "1994-01-02 00:00:00", "BirthDate": "1960-05-29 00:00:00", "City": "London", "Address": "Edgeham Hollow Winchester Way" }, { "EmployeeID": 8, "FirstName": "Laura", "LastName": "Callahan", "ReportsTo": 2, "Country": "USA", "Title": "Inside Sales Coordinator", "HireDate": "1994-03-05 00:00:00", "BirthDate": "1958-01-09 00:00:00", "City": "Seattle", "Address": "4726 - 11th Ave. N.E." }, { "EmployeeID": 9, "FirstName": "Anne", "LastName": "Dodsworth", "ReportsTo": 5, "Country": "UK", "Title": "Sales Representative", "HireDate": "1994-11-15 00:00:00", "BirthDate": "1966-01-27 00:00:00", "City": "London", "Address": "7 Houndstooth Rd." }];
                
        var source =
                {
                    dataType: "json",
                    dataFields: [
                        { name: 'EmployeeID', type: 'number' },
                        { name: 'ReportsTo', type: 'number' },
                        { name: 'FirstName', type: 'string' },
                        { name: 'LastName', type: 'string' },
                        { name: 'Country', type: 'string' },
                        { name: 'City', type: 'string' },
                        { name: 'Address', type: 'string' },
                        { name: 'Title', type: 'string' },
                        { name: 'HireDate', type: 'date' },
                        { name: 'BirthDate', type: 'date' }
                    ],
                    hierarchy:
                    {
                           keyDataField: { name: 'EmployeeID' },
                        parentDataField: { name: 'ReportsTo' }
                
                        
                    },
                    id: 'EmployeeID',
                    localData: employees
                };
        var dataAdapter = new $.jqx.dataAdapter(source);
        // create Tree Grid
        $("#treeGrid").jqxTreeGrid(
        {
            width: 850,
            theme: "arctic",
            source: dataAdapter,
            ready: function()
            {
               $("#treeGrid").jqxTreeGrid('expandAll');
      
            },
            sortable: true,
            filterable: true,
            columns: [
              { text: 'City', dataField: 'City', width: 120 },
              { text: 'Country', dataField: 'Country' },
              { text: 'FirstName', dataField: 'FirstName', width: 200 },
              { text: 'LastName', dataField: 'LastName', width: 120 },
              { text: 'Title', dataField: 'Title', width: 160 },
              { text: 'Birth Date', dataField: 'BirthDate', cellsFormat: 'd', width: 120 },
              { text: 'Hire Date', dataField: 'HireDate', cellsFormat: 'd', width: 120 },
              { text: 'Address', dataField: 'Address', width: 250 }
            ]
        });
        
                var applyFilter = function (dataField, dataVal) {
                    
                    var filtertype = 'stringfilter';
             
                    // create a new group of filters.
                    var filtergroup = new $.jqx.filter();
                        var filter_or_operator = 0;
                        var filtervalue = dataVal;
                        var filtercondition = 'contains';
                        var filter = filtergroup.createfilter(filtertype, filtervalue, filtercondition);
                        filtergroup.addfilter(filter_or_operator, filter);
    
                    // add the filters.
                    $("#treeGrid").jqxTreeGrid('addFilter', dataField, filtergroup);
                    // apply the filters.
                    $("#treeGrid").jqxTreeGrid('applyFilters');
                }
        
        $("#srep").click(function () {
            applyFilter('Title', 'Sales Representative');
        });
    
        $("#usa").click(function () {
            applyFilter('Country', 'USA');
        });
        
    });

    Regardless of that, you can apply only the filters that will work in the same was as they are applied from the UI i.e the condition between the columns is & always. You can only change the conditions between filters applied to the same column.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    rao
    Participant

    Thank you Peter,
    My search ended here.

    Regards,
    Rao.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.