Skip to content

Commit f3292df

Browse files
committed
Provide better example of handling dates for display and export.
1 parent f6e464f commit f3292df

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

config/searchWidget.js

+30-19
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
11
define([
22
'dojo/on',
3+
'dojo/_base/lang',
34
'dojo/date/locale'
4-
], function (on, locale) {
5+
], function (on, lang, locale) {
56

67
function formatDateTime (value) {
7-
var date = new Date(value);
8-
return locale.format(date, {
9-
formatLength: 'short'
10-
});
8+
if (value instanceof Date) {
9+
return locale.format(value, {
10+
formatLength: 'short'
11+
});
12+
}
13+
return '';
1114
}
1215

1316
function formatDate (value) {
14-
var date = new Date(value);
15-
return locale.format(date, {
16-
selector: 'date',
17-
formatLength: 'medium'
18-
});
17+
if (value instanceof Date) {
18+
return locale.format(value, {
19+
selector: 'date',
20+
formatLength: 'medium'
21+
});
22+
}
23+
return '';
24+
}
25+
26+
function getDateTime (value) {
27+
if (isNaN(value) || value === 0 || value === null) {
28+
return null;
29+
}
30+
return new Date(value);
1931
}
2032

2133
return {
@@ -67,7 +79,7 @@ define([
6779
label: 'Inspected',
6880
width: 150,
6981
get: function (object) { // allow export as a proper date
70-
return new Date(object.inspdate);
82+
return getDateTime(object.inspdate);
7183
},
7284
formatter: formatDateTime
7385
},
@@ -91,7 +103,7 @@ define([
91103
field: 'lastupdate',
92104
label: 'Updated',
93105
get: function (object) { // allow export as a proper date
94-
return new Date(object.lastupdate);
106+
return getDateTime(object.lastupdate);
95107
},
96108
formatter: formatDateTime
97109
}
@@ -123,7 +135,7 @@ define([
123135
{
124136
name: 'Hospital Name',
125137
label: 'Name',
126-
expression: '(NAME LIKE \'[value]%\')',
138+
expression: '(NAME LIKE \'%[value]%\')',
127139
placeholder: 'Enter the name of the hospital',
128140
required: true,
129141
minChars: 3
@@ -150,7 +162,7 @@ define([
150162
id: 'Action',
151163
field: 'OBJECTID',
152164
label: 'Action',
153-
width: 32,
165+
width: 60,
154166
sortable: false,
155167
exportable: false,
156168
renderCell: function (object, value, node) {
@@ -162,8 +174,7 @@ define([
162174
},
163175
{
164176
field: 'NAME',
165-
label: 'Name',
166-
width: 150
177+
label: 'Name'
167178
},
168179
{
169180
field: 'ADDRESS',
@@ -183,7 +194,7 @@ define([
183194
{
184195
field: 'ZIPCODE',
185196
label: 'Zip Code',
186-
width: 80
197+
width: 100
187198
},
188199
{
189200
field: 'TOTALADM',
@@ -193,9 +204,9 @@ define([
193204
{
194205
field: 'LASTUPDATE',
195206
label: 'Last Update',
196-
width: 100,
207+
width: 120,
197208
get: function (object) { // allow export as a proper date
198-
return new Date(object.LASTUPDATE);
209+
return getDateTime(object.LASTUPDATE);
199210
},
200211
formatter: formatDateTime
201212
}

0 commit comments

Comments
 (0)