NestedDataModelCollection and [CustomEntity] int property with PreviewTitle only showing ID
Hello,
As the title suggests, I'm trying to figure out a solution to show the name of the custom entity in the NestedDataModelCollection when it shows on the Admin UI for editing in the list. Right now, if I set the [PreviewTitle] attribute on the [CustomEntity] property like so:
On a ICustomEntityDataModel
[Display(Name = "Rankings")]
[NestedDataModelCollection(IsOrderable = true)]
public ICollection<SchoolRankingDataModel> Rankings { get; set; }
}
public class SchoolRankingDataModel : INestedDataModel
{
[Display(Description = "Ranking Category")]
[CustomEntity(RankingCategoryEntityDefinition.DefinitionCode)]
[Required]
[PreviewTitle]
public int RankingCategory { get; set; }
[Display(Description = "Score")]
[Required]
[PreviewDescription]
public decimal Score { get; set; }
[Display(Description = "Rank")]
[Required]
public int Rank { get; set; }
}
This only shows the CustomEntity ID on the Admin UI editing screen when viewing the list. Is there a way to configure this, or route in a custom way for the listing to show the custom entities [PreviewTitle] property itself? I have [PreviewTitle] set on a string property in the custom entity that is being selected, but this seems to be ignored, and either only uses the int property or if I take it off of the int property, shows nothing.
Thanks in advance for the advice!
Unfortunately thats not a supported scenario. The preview title will just show the raw value of the property it annotates, and is only documented as working on strings.
It's a reasonable feature request, but it gets a bit tricky with dependency graphs and circular references.
Thanks for the response Joel, I figured it would be something a bit difficult.
I guess an alternative solution could be, to provide a custom OptionSource, that saves the value as the name (though I lose hard linkage through ID for other portions where this data is used) - and put a unique name validation on the custom entities themselves.