带有jquery.ui滑块的jqGrid过滤器:值小于100时的奇怪行为

带有jquery.ui滑块的jqGrid过滤器:值小于100时的奇怪行为,jquery,jqgrid,Jquery,Jqgrid,我们已经在jqGrid之外使用jquery.ui组件(如按钮和滑块)实现了过滤(在webshop中)。列表(网格)的可用筛选器取决于当前处于活动状态的类别。当按下/使用按钮和滑块时,我们创建规则并将其添加到filters属性中,必要时将其删除 在大多数情况下,这就像一个符咒,但是当为包含100的值的类别创建特定过滤器时,如果我们使用滑块进行过滤,结果会出现一些奇怪的情况。一旦我们开始拉动滑块的下部,当较低的值大于最低值(即100,然后一切都按预期工作 当拉动滑块的下端时,我们向过滤器添加“ge”

我们已经在jqGrid之外使用jquery.ui组件(如按钮和滑块)实现了过滤(在webshop中)。列表(网格)的可用筛选器取决于当前处于活动状态的类别。当按下/使用按钮和滑块时,我们创建规则并将其添加到filters属性中,必要时将其删除

在大多数情况下,这就像一个符咒,但是当为包含<100到>100的值的类别创建特定过滤器时,如果我们使用滑块进行过滤,结果会出现一些奇怪的情况。一旦我们开始拉动滑块的下部,当较低的值大于最低值(即<100)但小于100时,整个结果集就会消失。在这种情况下,最小值为97,6,对于滑块上的值98和99,结果为空。但当滑块值变为100或更大时,结果是正确的。我还将值低于100的文章更改为>100,然后一切都按预期工作

当拉动滑块的下端时,我们向过滤器添加“ge”规则,当拉动高值端时,我们添加“le”规则

我们使用jqgrid 4.3.1,今天我也尝试了版本4.4.4,结果相同

如果这与jqGrid如何解释网格中的值有关,那么我们也使用瑞典语言环境

else if (dynamicFilters[l].Type == "slider") {
                            //Get the smallest and the biggest value that we should be able to filter on

                            //Parse the value so that there are no non-numberic characters, and also replace ',' with '.' so that it can be converted to a numeric value
                            var currentValue = property.Value.replace(/[^0-9.,]/g, '').replace(/[,]/g, '.');
                            var index = property.Value.indexOf(".");

                            if (index >= 0) {
                                currentValue = property.Value.substring(0, index);
                            }

                            currentValue = Number(currentValue);

                            //Specific case where no value has been set
                            if (dynamicFilters[l].Values[0] == 0 && dynamicFilters[l].Values[1] == 0) {
                                dynamicFilters[l].Values[0] = currentValue;
                                dynamicFilters[l].Values[1] = currentValue;
                            } else {
                                //Else check if the value is either smaller or larger than those in the array
                                if (dynamicFilters[l].Values[0] > currentValue) {
                                    dynamicFilters[l].Values[0] = currentValue;
                                }
                                if (dynamicFilters[l].Values[1] < currentValue) {
                                    dynamicFilters[l].Values[1] = currentValue;
                                }
                            }
                        }
更新(代码)

首先,我们从要显示在网格中的项目集合中获取最小值和最大值

else if (dynamicFilters[l].Type == "slider") {
                            //Get the smallest and the biggest value that we should be able to filter on

                            //Parse the value so that there are no non-numberic characters, and also replace ',' with '.' so that it can be converted to a numeric value
                            var currentValue = property.Value.replace(/[^0-9.,]/g, '').replace(/[,]/g, '.');
                            var index = property.Value.indexOf(".");

                            if (index >= 0) {
                                currentValue = property.Value.substring(0, index);
                            }

                            currentValue = Number(currentValue);

                            //Specific case where no value has been set
                            if (dynamicFilters[l].Values[0] == 0 && dynamicFilters[l].Values[1] == 0) {
                                dynamicFilters[l].Values[0] = currentValue;
                                dynamicFilters[l].Values[1] = currentValue;
                            } else {
                                //Else check if the value is either smaller or larger than those in the array
                                if (dynamicFilters[l].Values[0] > currentValue) {
                                    dynamicFilters[l].Values[0] = currentValue;
                                }
                                if (dynamicFilters[l].Values[1] < currentValue) {
                                    dynamicFilters[l].Values[1] = currentValue;
                                }
                            }
                        }
_filterDynamic函数的工作原理如下:

_applyFilter: function (that, property, type, value) {
    var myfilter = {};

    //Get a new fresh filter or the current one
    if (that.data("Filter") == null) {
        myfilter.filter = { groupOp: "AND", rules: [] };
        myfilter.HasPriceFilter = false;
        myfilter.HasBrandFilter = false;
        myfilter.HasSmallFilter = false;
        myfilter.HasMediumFilter = false;
        myfilter.HasLargeFilter = false;
        myfilter.HasAdditionFilter = false;
        myfilter.HasMiscFilter = false;
    } else {
        myfilter = that.data("Filter");
    }

    myfilter = articleListFilter._filterDynamic(myfilter, property, type, value);

    //Must reload here so that the paging won't get stuck on a page that has no items. Must be done before the filter is set.
    $("#articles").trigger("reloadGrid");

    that.data("Filter", myfilter);

    articleListFilter._setFilter(that, myfilter.filter, 1);
}
else if (type == "slider") {
        //Need to check if there already is a filter for the same property and type, if the data should be changed or pushed into the rules array
        var addMinRule = true;
        var addMaxRule = true;
        var minValue = $("#" + property).slider("option", "min");
        var maxValue = $("#" + property).slider("option", "max");

        for (var j = 0; j < myFilter.filter.rules.length; j++) {
            var rule = myFilter.filter.rules[j];

            if (rule.field == property && rule.op == "ge") {
                rule.data = value[0];
                addMinRule = false;
            }
            else if (rule.field == property && rule.op == "le") {
                rule.data = value[1];
                addMaxRule = false;
            }
        }

        if (addMinRule) {
            myFilter.filter.rules.push({ field: property, op: "ge", data: value[0] });
        }

        if (addMaxRule) {
            myFilter.filter.rules.push({ field: property, op: "le", data: value[1] });
        }

        if (value[0] == minValue || value[1] == maxValue) {
            for (var k = 0; k < myFilter.filter.rules.length; k++) {
                var removeRule = myFilter.filter.rules[k];

                if (removeRule.field == property && removeRule.op == "ge") {
                    if (value[0] == minValue) {
                        myFilter.filter.rules.splice(k, 1);
                    }
                }
                else if (removeRule.field == property && removeRule.op == "le") {
                    if (value[1] == maxValue) {
                        myFilter.filter.rules.splice(k, 1);
                    }
                }
            }
        }
    }
else if(类型==“滑块”){
//需要检查是否已经存在针对相同属性和类型的筛选器,是否应该更改数据或将数据推送到规则数组中
var addMinRule=true;
var addMaxRule=true;
var minValue=$(“#”+属性).slider(“选项”,“最小”);
var maxValue=$(“#”+属性).slider(“选项”,“最大值”);
对于(var j=0;j
欢迎任何帮助或类似的故事


你好,比约恩

你好,比约恩,你有上面描述的例子的代码吗?@jeffery__the_wind我已经添加了一些用于创建和执行实际过滤的代码,希望你能从中读到一些东西!谢谢