Skip to content

Commit 72161ce

Browse files
committed
Add default column formatting based on the result's field type.
1 parent 056e61b commit 72161ce

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

config/table.css

-3
This file was deleted.

config/table.js

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
1-
define([
2-
'esri/urlUtils',
3-
], function (urlUtils) {
4-
5-
function formatDateTime (value) {
6-
var date = new Date(value);
7-
return locale.format(date, {
8-
formatLength: 'short'
9-
});
10-
}
11-
12-
require(['xstyle/css!./config/table.css']);
1+
define([], function () {
132

143
return {
154
isDebug: false,

widgets/AttributesTable/_GridMixin.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ define([
44
'dojo/has',
55
'dojo/_base/array',
66
'dojo/date/locale',
7+
'dojo/number',
78

89
'dojo/store/Memory',
910
'dgrid/Grid', // http://dojofoundation.org/packages/dgrid/
@@ -19,6 +20,7 @@ define([
1920
has,
2021
array,
2122
locale,
23+
number,
2224

2325
Memory,
2426
Grid,
@@ -268,6 +270,14 @@ define([
268270
formatLength: 'short'
269271
});
270272
}
273+
function formatNumber (value) {
274+
return number.format(value);
275+
}
276+
function formatSingleDouble (value) {
277+
return number.format(value, {
278+
places: 3
279+
});
280+
}
271281

272282
var excludedFields = ['objectid', 'esri_oid', 'shape', 'shape.len', 'shape.area', 'shape.starea()', 'shape.stlength()', 'st_area(shape)', 'st_length(shape)'];
273283
var columns = [], col, nameLC = null;
@@ -279,15 +289,22 @@ define([
279289
id: field.name,
280290
field: field.name,
281291
label: field.alias,
292+
style: 'white-space:nowrap;overflow:hidden;text-overflow:ellipsis;',
282293
width: 100
283294
};
284295
switch (field.type) {
285296
case 'esriFieldTypeString':
286-
col.width = 200;
297+
col.width = 150;
287298
break;
288-
case "esriFieldTypeSmallInteger", "esriFieldTypeInteger", "esriFieldTypeSingle":
299+
case 'esriFieldTypeSmallInteger':
300+
case 'esriFieldTypeInteger':
301+
col.formatter = formatNumber;
302+
col.style += 'text-align:right;';
289303
break;
290-
case "esriFieldTypeDouble":
304+
case 'esriFieldTypeSingle':
305+
case 'esriFieldTypeDouble':
306+
col.formatter = formatSingleDouble;
307+
col.style += 'text-align:right;';
291308
break;
292309
case 'esriFieldTypeDate':
293310
col.width = 150;

0 commit comments

Comments
 (0)