Select to view content in your preferred language

show domain in dgrid/OnDemandGrid

4634
11
07-15-2015 10:04 AM
AuraRamos_Lora1
Emerging Contributor

Could you help me, please to show domain in dgrid, this is functionally in infowindow but in grid puts the code,  not the description.of domain.

var outFieldsProy = ["PROYECTO", "NOMBRE", "ESC250", "AERONAVE"]

var gridProy = new (declare([Grid, Selection,ColumnHider, ColumnReorder, ColumnResizer]))({

      bufferRows : Infinity,

      columns : {

        PROYECTO : "Proyecto",

        NOMBRE : "Nombre",

        ESC250 : "Escala 250",

        AERONAVE : "Aeronave"

}

    }, "divGrid");

function populateGrid(results) {
            // var gridData;

            dataQuakes = arrayUtils.map(results.features, function (feature) {
                return {
                    "PROYECTO": feature.attributes[outFieldsProy[0]],
                    "NOMBRE": feature.attributes[outFieldsProy[1]],
                    "ESC250": feature.attributes[outFieldsProy[2]],
                    "AERONAVE": feature.attributes[outFieldsProy[3]]

                    };

            });

          

            var memStore = new Memory({

                data: dataQuakes

            });

            gridProy.set("store", memStore)           

        }

Thanks

0 Kudos
11 Replies
thejuskambi
Frequent Contributor

you should find something here QueryTask and coded domain values

AuraRamos_Lora1
Emerging Contributor

Thank you thejus kambi

This function  _getCodedValue: function (layer, fieldName, fieldValue, typeID)       must be before this?:

function populateGrid(results) {
            // var gridData;
            dataQuakes = arrayUtils.map(results.features, function (feature) {
                return {
                    "PROYECTO": feature.attributes[outFieldsProy[0]],
                    "NOMBRE": feature.attributes[outFieldsProy[1]],
                    "ESC250": feature.attributes[outFieldsProy[2]],
                    "AERONAVE": feature.attributes[outFieldsProy[3]]
                    };
            });

and other question,  ¿which is typeID?

Regards

0 Kudos
thejuskambi
Frequent Contributor

Ignore that as you might not have it. It is to be use when you have a subtypes in FeatureLayer.

You can use the fields property of the query result. Select the field which has domain.

var field = results.fields["< field name  >"]

var codedValueDomain = field.domain;

and use this domain and get the code value, while looping through the features and prepare the data for grid.

AuraRamos_Lora1
Emerging Contributor

I´m sorry, but I have other question.

My query result is a featureset. how can I convert this to fields type?

//Inicializa el query
            var queryProy = new Query();
            queryProy.geometry = geometryInput;
            //Wire the layer's selection complete event
            operationsPolygonLayer.on("selection-complete", populateGrid);
            // Transforma la selección
            operationsPolygonLayer.selectFeatures(queryProy, FeatureLayer.SELECTION_NEW);

because

var field = results.fields["AERONAVE"];

is undefined              

Thanks again
Regards

0 Kudos
thejuskambi
Frequent Contributor

I thought you are using QueryTask to get the results. Now I see you are using featureLayer. The FeatureLayer has fields property use that instead.

0 Kudos
RickeyFight
MVP Regular Contributor

I am having a hard time getting coded domains to show up.

What part of the code did you put this into:

var field = feature.fields["<Priority>"]

var codedValueDomain = field.domain;

I am using this template

DataGrid with zoom button | ArcGIS API for JavaScript

0 Kudos
thejuskambi
Frequent Contributor

Hello Rickey,

You need to do if before you set the data to dgrid. like below

statesLayer.on("load", function(evt) {
          var query = new Query();
          query.where = "1=1";
          evt.layer.queryFeatures(query, function(featureSet) {
            var items = array.map(featureSet.features, function(feature) {
                   var attributes = lang.clone(feature.attributes);
                   var fields = statesLayer.fields;
                   //Replace the attributes values for domain values here.
                   return attributes;
            });

            //idProperty must be set manually if value is something other than 'id'
            var memStore = new Memory({
              data: items,
              idProperty: "ObjectID"
            });
            window.grid.set("store", memStore);
            window.grid.set("sort", "STATE_NAME");

            grid.on(".field-ObjectID:click", function(e) {
              //retrieve the ObjectId when someone clicks on the magnifying glass
              if (e.target.alt) {
                zoomRow(e.target.alt);
              }
            });
          });
        });

Thejus

RickeyFight
MVP Regular Contributor

I get an error of:

Cannot read property '<Priority>' of undefined

where priority is my field name

0 Kudos
thejuskambi
Frequent Contributor

you should try without the "<" ">" signs. also feature does not contain the fields property. if you see my code, I am getting the fields from the stateLayer and not feature.