jQWidgets Forums

jQuery UI Widgets Forums ASP .NET MVC jqxGrid Server Paging, Sorting and Filtering

Tagged: , ,

This topic contains 7 replies, has 2 voices, and was last updated by  Exlord 7 years, 6 months ago.

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

  • Exlord
    Participant

    Hi,
    Have you actually tested the code in this page :
    https://www.jqwidgets.com/jquery-widgets-documentation/documentation/asp.net-integration/asp.net-grid-server-side-paging-sorting-filtering-mvc3.htm?search=

    private string BuildQuery(System.Collections.Specialized.NameValueCollection query)
            {
                var filtersCount =  int.Parse(query.GetValues("filterscount")[0]);
                var queryString = @"SELECT * FROM Orders ";
                var tmpDataField = "";
                var tmpFilterOperator = "";
                var where = "";
                if (filtersCount > 0)
                {
                    where = " WHERE (";
                }
                for (var i = 0; i < filtersCount; i += 1)
                {
                    var filterValue = query.GetValues("filtervalue" + i)[0];
                    var filterCondition = query.GetValues("filtercondition" + i)[0];
                    var filterDataField = query.GetValues("filterdatafield" + i)[0];
                    var filterOperator = query.GetValues("filteroperator" + i)[0];
                    if (tmpDataField == "")
    		        {
    			        tmpDataField = filterDataField;			
    		        }
    		        else if (tmpDataField != filterDataField)
    		        {
    			        where += ") AND (";
    		        }
    		        else if (tmpDataField == filterDataField)
    		        {
                        if (tmpFilterOperator == "")
                        {
                            where += " AND ";
                        }
                        else
                        {
                            where += " OR ";
                        }
    		        }
    		        // build the "WHERE" clause depending on the filter's condition, value and datafield.
    		        where += this.GetFilterCondition(filterCondition, filterDataField, filterValue);
    		        if (i == filtersCount - 1)
    		        {
    			        where += ")";
    		        }
    		        tmpFilterOperator = filterOperator;
    		        tmpDataField = filterDataField;
                }
                queryString += where;
                return queryString;
            }

    you are totally ignoring and never actually using the filterOperator‘s value.

    I created this filter

    
                var filtergroup = new $.jqx.filter();
                var filter_and_operator = 0;
    
                var date = dateFromHidden.val().trim();
                if(date && date.length){
                    var filter = filtergroup.createfilter('datefilter', date, 'GREATER_THAN_OR_EQUAL');
                    filtergroup.addfilter(filter_and_operator, filter);
                }
    
                date = dateToHidden.val().trim();
                if(date && date.length){
                    var filter = filtergroup.createfilter('datefilter', date, 'LESS_THAN_OR_EQUAL');
                    filtergroup.addfilter(filter_and_operator, filter);
                }
    
                _grid.jqxGrid('addfilter', 'RequestDate', filtergroup);
                _grid.jqxGrid('applyfilters');
    

    which resulted in a query where the 2 dates were joined by a OR instead of AND!
    And coould you expand this to include filtergroups too?


    Peter Stoev
    Keymaster

    Yes, we have tested it and it works well. The filterOperator value is not ignored if you look at the code.


    Exlord
    Participant

    This is the only place you have ever used it :

    if (tmpFilterOperator == "") {
      where += " AND ";
    } else {
      where += " OR ";
    }

    correct me if I’m wrong, but you are not actually using its value!!!

    Shouldn’t it be something like this :

              if (tmpFilterOperator == "0") {
                where += " AND ";
              } else {
                where += " OR ";
              }

    Exlord
    Participant

    The php code seems to be valid :

    if ($tmpfilteroperator == 0)


    Peter Stoev
    Keymaster

    I think you are missing this one: tmpFilterOperator = filterOperator;


    Exlord
    Participant

    Check the php code please if ($tmpfilteroperator == 0) in the ASP.NET version you always comparing the operator to a empty string tmpFilterOperator == "".

    tmpFilterOperator == "" IS NOT EQUAL to tmpFilterOperator == 0 NOR TO tmpFilterOperator == "0", You don’t care WHAT value tmpFilterOperator has only that its empty or not???

    tmpFilterOperator == "" will always equals FALSE after the first loop!!!!


    Peter Stoev
    Keymaster

    The tmpFilterOperator is assigned to “” so it is “”. PHP and .NET are different and implementations are different.


    Exlord
    Participant

    The code in the .Net sample is INCORRECT, do whatever you wish with it, I am done explaining it to you.

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

You must be logged in to reply to this topic.