jQWidgets Forums
jQuery UI Widgets › Forums › ASP .NET MVC › jqxGrid Server Paging, Sorting and Filtering
This topic contains 7 replies, has 2 voices, and was last updated by Exlord 7 years, 6 months ago.
-
Author
-
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 ofAND
!
And coould you expand this to include filtergroups too?Yes, we have tested it and it works well. The filterOperator value is not ignored if you look at the code.
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 "; }
The php code seems to be valid :
if ($tmpfilteroperator == 0)
I think you are missing this one: tmpFilterOperator = filterOperator;
Check the php code please
if ($tmpfilteroperator == 0)
in the ASP.NET version you always comparing the operator to a empty stringtmpFilterOperator == ""
.tmpFilterOperator == ""
IS NOT EQUAL totmpFilterOperator == 0
NOR TOtmpFilterOperator == "0"
, You don’t care WHAT valuetmpFilterOperator
has only that its empty or not???tmpFilterOperator == ""
will always equals FALSE after the first loop!!!!The tmpFilterOperator is assigned to “” so it is “”. PHP and .NET are different and implementations are different.
The code in the .Net sample is INCORRECT, do whatever you wish with it, I am done explaining it to you.
-
AuthorPosts
You must be logged in to reply to this topic.