Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am following this ESRI tutorial to display information from a related table for the selected features. The example in itself for my project works fine, however, my data include two Date fields and when I display them on the right side grid, I see something like "1237507200000" as starting date and "1237161600000" as ending date.

I understand I have to format this esriFieldTypeDate so I can display it as a text field like "YYYY-MM-DD", but I don't know how. It is important to highlight that this related records are stored in a dojo.data.ItemFileReadStore as in the example.

Please, does anyone know how to do this?

Thanks!

share|improve this question
add comment

1 Answer 1

up vote 5 down vote accepted

"1237507200000" is a date in tics, just use a regular js-date object to convert to string. When you map the items object from feature.attributes object, you can do the conversion. For example something like this:

var items = dojo.map(fset.features, function(feature) {
            feature.attributes.date = Date(  feature.attributes.date ).toLocaleString() ;
            return feature.attributes;
          });

 var data = {
            identifier: "OBJECTID",  //This field needs to have unique values
            label: "OBJECTID", //Name field for display. Not pertinent to a grid but may be used elsewhere.
            items: items
          };

          //Create data store and bind to grid.
          store = new dojo.data.ItemFileReadStore({ data:data });
          grid.setStore(store);
          grid.setQuery({ OBJECTID: '*' });
        });
share|improve this answer
    
Rather than looping through all of the features I would use a formatter on the field. For a large dataset you are adding an uncesssary loop through the data. See Formatter on dojotoolkit.org/reference-guide/1.8/dojox/grid/DataGrid.html –  David Wilton Feb 13 '13 at 12:55
    
Thanks, it simply works perfectly!! I changed the date modifier to "datePattern: 'MMMM d, y' " to match my criteria. :-) –  iamgin Feb 14 '13 at 11:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.