javascript - jqGrid如何应用自定义过滤/搜索

标签 javascript jqgrid

我有一个带有过滤器工具栏的 jqGrid。在我的一个专栏中,我想在“过滤器测试”的位置进行搜索,调用我的自定义函数,并且显然返回 true 表示是,它通过了 false 表示否。

jqGrid 可以做到这一点吗?如果可以,怎么做?

最佳答案

使用 jqGrid 的免费分支,您可以使用以下内容

在您的 colModel 中添加值 searchoptions,如下所示:

{name:'FIELD',width:120,searchoptions:{ sopt: ["cust"] },label:"Field name"}

然后将以下属性添加到jqGrid

customSortOperations: {
    // the properties of customSortOperations defines new operations 
    // used in postData.filters.rules items as op peroperty
    cust:{
           operand: "Custom",// will be displayed in searching Toolbar for example
           text: "Custom",    // will be shown in Searching Dialog or operation menu in searching toolbar

           filter: function (options) {
                        // The method will be called in case of filtering on the custom operation "cust"
                        // All parameters of the callback are properties of the only options parameter.
                        // It has the following properties:
                        //     item        - the item of data (exacly like in mydata array)
                        //     cmName      - the name of the field by which need be filtered
                        //     searchValue - the filtered value typed in the input field of the searching toolbar

                        // Get cell data as lowercase
                        var fieldData = options.item[options.cmName].toLowerCase(),
                        // Get search terms all in lowercase
                        terms = $.map(options.searchValue.split(" "), function(val){ return $.trim(val).toLocaleLowerCase(); }),
                        // A match found
                        match = false;
                        // Loop through terms and see if there is a match in the row cell data
                        $.each(terms, function(i,v)
                        {
                            if(fieldData.indexOf(v) != -1)
                            {
                                match = true;
                                // Quit the each loop
                                return false;
                            }
                        });
                        return match;
                    }
                }
            },

关于javascript - jqGrid如何应用自定义过滤/搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54280291/

相关文章:

jquery - jqgrid 在触发重新加载时不提交重置页面值

javascript - JQuery 中的计算给出结果 "NaN"

javascript - 使用 ng-bind 时更新指令中的数据

jQGrid 拖放行检查

javascript - jqgrid 自定义格式化程序 : The custom formatter always returns the last row of the grid. 为什么?

javascript - JQGrid 格式化时显示错误的日期

javascript - mootools : I want to traverse following array in mootools

javascript - 仅适用于数字和单个点的正则表达式

javascript - 禁用在按 Tab 键切换到下一个元素时选择语义 UI 下拉选项

jquery - free-jggrid treeGrid 在表格底部展开