無料の jqGrid にカスタム フィルタリング機能を導入して、若者のようなシナリオを簡単に実装できるようにしました。答えは、そのような実装の例を提供します。
あなたの場合、たとえばDate only "equal"
短い名前で新しい比較操作を定義し、短い名前で比較操作を定義できます。オプションのコードは次のようになります。"deq"
Date only "not equal"
dne
customSortOperations
customSortOperations: {
deq: {
operand: "==",
text: "Date only \"equal\"",
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);
return fieldData.getFullYear() === searchValue.getFullYear() &&
fieldData.getMonth() === searchValue.getMonth() &&
fieldData.getDate() === searchValue.getDate();
}
},
dne: {
operand: "!=",
text: "Date only \"not equal\"",
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);
return fieldData.getFullYear() !== searchValue.getFullYear() ||
fieldData.getMonth() !== searchValue.getMonth() ||
fieldData.getDate() !== searchValue.getDate();
}
}
}
"deq"
newおよびoperationを使用できるようにするには、日付のある列の of に含める"dne"
必要があります。sopt
searchoptions
デモでは上記のコードを使用します。入力データには、 、 、 の 3 つの日付が含まれて"2015-04-15T15:31:49.357"
い"2015-04-15T21:15:40.123"
ます"2015-04-15"
。
var mydata = [
{ id: "10", invdate: "2015-04-15T15:31:49.357", name: "test1",... },
{ id: "20", invdate: "2015-04-15T21:15:40.123", name: "test2",... },
{ id: "30", invdate: "2015-04-15", name: "test3", ...},
...
]
15-Apr-2015
3 つの行すべてを表示することによるフィルタリング:

別のデモでは実質的に同じコードが使用されていますが、日付が完全な日付/時刻形式で表示されます。それにもかかわらず、フィルタリングは機能します。デモでは GitHub から最新の無料の jqGrid ソースを使用していることに注意してください。デモを機能させるためにコードに小さな変更を加えたので、これは本当に必要です。parseDate
