free-jqgrid 中的日期 "less but not empty" 自定义搜索

Date "less but not empty" custom search in free-jqgrid

我正在使用 free-jqgrid 4.15.4 来显示数据。我需要使用 Date less but not empty 过滤器搜索日期列,但它没有正确过滤。结果它给了我比搜索日期大的日期。

以下代码用于日期列中的自定义过滤器:

customSortOperations: {

dlne: {
                operand: "<!=''",
                text: "Date less but not empty",
                filter:function (options) {
                    var p = this.p, iCol = p.iColByName[options.cmName], cm = p.colModel[iCol],
                        newformat = cm.formatoptions != null && cm.formatoptions.newformat ?
                                cm.formatoptions.newformat :
                                $(this).jqGrid("getGridRes", "formatter.date.newformat"),
                        srcformat = cm.formatoptions != null && cm.formatoptions.srcformat ?
                                cm.formatoptions.srcformat :
                                $(this).jqGrid("getGridRes", "formatter.date.srcformat"),
                        fieldData = $.jgrid.parseDate.call(this, srcformat, options.item[options.cmName]),
                        searchValue = $.jgrid.parseDate.call(this, newformat, options.searchValue);
                    var retFData = convertD(fieldData), t = new Date(retFData);
                    if ((retFData.getFullYear() < searchValue.getFullYear()) && (retFData.getMonth() < searchValue.getMonth()) && (retFData.getDate() < searchValue.getDate())) {
                        return true
                    }
                }
           },
}

我用来将字符串转换为日期格式的convert函数如下所示:

function convertD(dateField) {
var date = new Date(dateField),
    mnth = ("0" + (date.getMonth() + 1)).slice(-2),
    day = ("0" + date.getDate()).slice(-2);
// year= (date.getFullYear())

var retVal = [day, mnth, date.getFullYear()].join("/");
return retVal;
}

我借鉴了的想法并做了一些修改,但似乎无济于事。因此请求社区对此提供帮助。

dlne 的代码可以固定为例如以下内容:

dlne: {
    operand: "<!=''",
    text: "Date less but not empty",
    filter: function (options) {
        var p = this.p, iCol = p.iColByName[options.cmName], cm = p.colModel[iCol],
            newformat = cm.formatoptions != null && cm.formatoptions.newformat ?
                    cm.formatoptions.newformat :
                    $(this).jqGrid("getGridRes", "formatter.date.newformat"),
            srcformat = cm.formatoptions != null && cm.formatoptions.srcformat ?
                    cm.formatoptions.srcformat :
                    $(this).jqGrid("getGridRes", "formatter.date.srcformat"),
            fieldData, searchValue;

        // the exact condition to test for "empty" depend on the format of your data
        if (!options.item[options.cmName]) {
            return false; // ignore empty data
        }

        fieldData = $.jgrid.parseDate.call(this, srcformat, options.item[options.cmName]);
        searchValue = $.jgrid.parseDate.call(this, newformat, options.searchValue);
        return fieldData.getFullYear() < searchValue.getFullYear() ||
            (fieldData.getFullYear() === searchValue.getFullYear() &&
                fieldData.getMonth() < searchValue.getMonth()) ||
            (fieldData.getFullYear() === searchValue.getFullYear() &&
                fieldData.getMonth() === searchValue.getMonth() &&
              fieldData.getDate() < searchValue.getDate());
    }
}

https://jsfiddle.net/OlegKi/51vfn4k9/11/