Free jqGrid - A custom filter rule for “empty” and “not empty” [closed]

自古美人都是妖i 提交于 2019-11-29 16:43:40

Thanks for pointing of the problem of definition custom unary operations. I committed the changes of the code of free jqGrid to allow to specify the custom unary operations inside of new option customUnaryOperations.

The demo defines two custom filtering operations: "em" ("is empty") and "nm" ("isn't empty") and use the operations in "Amount" and "Notes" columns. The column "Notes" uses additionally the standard (predefined) "nu" ("is null") and "nn" ("is not null") operations. The column "amount" uses

searchoptions: {sopt: ["eq", "ne", "em", "nm"]}

and the column "note" uses

searchoptions: {sopt: ["cn", "bw", "ew", "eq", "bn", "nc", "en", "nu", "nn", "em", "nm"]}

additionally the demo uses customSortOperations and new customUnaryOperations:

customUnaryOperations: ["em", "nm"],
customSortOperations: {
    em: {
        operand: "=''",
        text: "is empty",
        filter: function (options) {
            var v = options.item[options.cmName];
            if (v === undefined || v === "") {
                return true;
            }
        }
    },
    nm: {
        operand: "!=''",
        text: "isn't empty",
        filter: function (options) {
            var v = options.item[options.cmName];
            if (v !== undefined && v !== "") {
                return true;
            }
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!