Opened 6 years ago

Closed 5 years ago

#17383 closed defect (patchwelcome)

EnhancedGrid filter is empty does not work with empty Date type

Reported by: smckeon Owned by: Evan
Priority: undecided Milestone: tbd
Component: DojoX Grid Version: 1.8.0
Keywords: Cc:
Blocked By: Blocking:

Description

We have a grid with a date column, defined like this:

{ name: "Rcvd Dte", field: "receivedDate", datatype:"date", width: '60px',

formatter: formatDate, dataTypeArgs: {

datePattern: "yyyy-MM-dd"

}

},

If the date value is empty we are printing out an empty string "". So some of the cells have a value and some are empty.

If we then use the filter plugin to filter by "Rcvd Dte" where value "is empty" no results are returned. Expected to have rows returned that have empty "Rcvd Dte".

It appears that isEmpty is not getting called, and thus results in a FALSE evaluation.

I traced this to the _convertData method in the file: /dojo/grid/enhanced/plugins/filter/_DataExprs.js

_convertData: function(/* anything */dataValue){ summary: override from _DataExpr

if(dataValue instanceof Date){

return dataValue;

}else if(typeof dataValue == "number"){

return new Date(dataValue);

}else{

var res = dateLocale.parse(String(dataValue), lang.mixin ({selector: this._name}, this._convertArgs)); if(!res){

throw new Error("Datetime parse failed: " + dataValue);

} return res;

}

},

The _convertData method will throw an error when you pass in an empty string. The error breaks the execution before isEmpty can be called. Because isEmpty is never called it results in a false evaluation, which is incorrect.

Change History (3)

comment:1 Changed 6 years ago by bill

Component: GeneralDojoX Grid
Owner: set to Evan

comment:2 Changed 6 years ago by smckeon

FYI, this bug also exists in 1.9.1.

We have a work-around, but would prefer to see this fixed in the source. Our work-around is to override the _DataExprs.DateExpr? _convertData method. In our version we comment out the "throw new Error(...)" and replace it with a "console.log(...)".

With the work-around we are successfully able to filter an empty date column with the "is empty" filter.

	/***
		override date parsing method to correct DOJO defect - SMM
		DOJO:
		https://bugs.dojotoolkit.org/ticket/17383
	***/
	require(["dojo/enhancedSearch"], function(){
		require([
		 	"dojo/_base/lang", 
		 	"dojo/date/locale", 
		 	"dojox/grid/enhanced/plugins/filter/_DataExprs"
		 	], 
		 	function(lang, dateLocale, _DataExprs){	
			    lang.extend(_DataExprs.DateExpr, {
					_convertData: function(/* anything */dataValue){
						// summary:
						//		override from _DataExpr
						if(dataValue instanceof Date){
							return dataValue;
						}else if(typeof dataValue == "number"){
							return new Date(dataValue);
						}else{
							var res = dateLocale.parse(String(dataValue), lang.mixin({selector: this._name}, this._convertArgs));
							if(!res){
								//throw new Error("Datetime parse failed: " + dataValue);
								console.log("Datetime parse failed: " + dataValue);
							}
							return res;
						}
					}
			    });
			});
		});

comment:3 Changed 5 years ago by bill

Resolution: patchwelcome
Status: newclosed

DojoX Grid and EnhancedGrid? are deprecated in favor of dgrid and gridx.

You should upgrade your code to use one of those two grids.

We will consider patches to the old DojoX Grid code though.

Note: See TracTickets for help on using tickets.