Custom Filter records in Free-jqgrid 4.15.4

牧云@^-^@ 提交于 2019-12-24 08:05:39

问题


I have one question regarding custom filters in free jqGrid 4.15.4. I want to implement a search functionality where if I select 'less than but not null or empty' filter then it should show only rows of records which column isn't null or empty. I am able to create custom filter which gives 'is null' or 'isn't null' from this thread. But when I tried to create for mine requirement, I wasn't able to figure out what operator I have to use for 'less than but not null or empty'.

for example, I have used this code sample to create custom filter:

 customUnaryOperations: ["lne"],
 customSortOperations: {
           lne: {
                operand: "<!=''",
                text: "less but not empty",
                filter: function (options) {
                    var v = options.item[options.cmName];
                    if (v !== undefined && v !== "") {
                        return true;
                    }
                }
            }

The above operator I've used in search option toolbar.

searchoptions: {
                     searchOperators: true,
                     sopt: ['eq', 'lt', 'gt','lne'],
                 }, search: true, 

Meanwhile, I don't want to use formatter: "integer" (suggested here) as this only assigns 0 to all null record column cells, and still visible in records whenever one selects 'less than' filter .

For reference, I've created one fiddle which consists of the requirement and two images for more clarity. So, Can anyone help me out on this? I hope I'vent re-asked this again.

Thank you in advance.


回答1:


The code of the filter could be like the following

customSortOperations: {
    lne: {
        operand: "<!=''",
        text: "less but not empty",
        filter: function (options) {
            var v = options.item[options.cmName];

            if (v !== undefined && v !== "" &&
                    parseFloat(v) < parseFloat(options.searchValue)) {
                return true;
            }
        }
    }
}

See modified demo https://jsfiddle.net/OlegKi/x3fger4z/17/



来源:https://stackoverflow.com/questions/52705227/custom-filter-records-in-free-jqgrid-4-15-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!