Select to view content in your preferred language

Reorder Fields in Attribute table using ArcGIS Pro SDK

787
5
Jump to solution
08-17-2024 08:22 AM
Teddytedo
Emerging Contributor

Any API in ArcGIS Pro SDK to set the layer attribute field order. Manually Data Design used or Arcpy  also another option. However, I did not see any API in Arcpro SDK. I checked   "SetFieldOrderAsync" but it required the active table view. But I plan to implement the order for many layers after adding the features to the map.

 

Thank you for the advice 

2 Solutions

Accepted Solutions
Teddytedo
Emerging Contributor

Ok, now I used the idea from the link you provided ... "Reordered field descriptions". What I did here is, I got the field description (list of field object) from the layer and reordered them in the new list of field descriptions...then I used the SetFieldDiscriptions method and now all looks good. 

I would love to learn if there is another better option to reorder the layer field in the attribute table.

 Thank you @GKmieliauskas 

View solution in original post

EricElder
Occasional Contributor

I had no success with SetFieldOrderAsync.  I ended up with the same solution as you did.  Something like below:

theCIMBaseLayer = layer.GetDefinition();
theCIMFeatLayer = (CIMFeatureLayer)theCIMBaseLayer;
theFieldDesc = theCIMFeatLayer.FeatureTable.FieldDescriptions;
theFieldList = theFieldDesc.ToList();

int theNum = 1;
theFieldDescNew = new CIMFieldDescription[theFieldDesc.Length];

foreach (CIMFieldDescription item in theFieldList)
{
    if (item.FieldName == "Name")
    {
        theFieldDescNew.SetValue(item, 0);
    }
    else
    {
        theFieldDescNew.SetValue(item, theNum);
    }
    theNum += 1;
}
theCIMFeatLayer.FeatureTable.FieldDescriptions = theFieldDescNew;
layer.SetDefinition(theCIMFeatLayer);

 

View solution in original post

0 Kudos
5 Replies
GKmieliauskas
Esri Regular Contributor

Hi, 

Look at the Community solution here. Maybe it could help you.

0 Kudos
Teddytedo
Emerging Contributor

Hi , 

I am interested in the layers on the map level, not the database level. The community solution has suggestions on database level but layer level. 

0 Kudos
Teddytedo
Emerging Contributor

Ok, now I used the idea from the link you provided ... "Reordered field descriptions". What I did here is, I got the field description (list of field object) from the layer and reordered them in the new list of field descriptions...then I used the SetFieldDiscriptions method and now all looks good. 

I would love to learn if there is another better option to reorder the layer field in the attribute table.

 Thank you @GKmieliauskas 

EricElder
Occasional Contributor

I had no success with SetFieldOrderAsync.  I ended up with the same solution as you did.  Something like below:

theCIMBaseLayer = layer.GetDefinition();
theCIMFeatLayer = (CIMFeatureLayer)theCIMBaseLayer;
theFieldDesc = theCIMFeatLayer.FeatureTable.FieldDescriptions;
theFieldList = theFieldDesc.ToList();

int theNum = 1;
theFieldDescNew = new CIMFieldDescription[theFieldDesc.Length];

foreach (CIMFieldDescription item in theFieldList)
{
    if (item.FieldName == "Name")
    {
        theFieldDescNew.SetValue(item, 0);
    }
    else
    {
        theFieldDescNew.SetValue(item, theNum);
    }
    theNum += 1;
}
theCIMFeatLayer.FeatureTable.FieldDescriptions = theFieldDescNew;
layer.SetDefinition(theCIMFeatLayer);

 

0 Kudos
Teddytedo
Emerging Contributor

hi @EricElder 

Great you tested that on your end. The SetFieldOrderAsync only works if you have an active attribute view. I don't think it even updates the layer file once applied to the active attribute view.

0 Kudos