Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Trusha Savsani 15 posts 94 karma points
    Jul 25, 2017 @ 13:52
    Trusha Savsani
    0

    List name field of reference table instead of Id in Ui-O-Matic table

    Hi,

    I am using Ui-O-Matic. It is working really nice. But problem is in listing records of table.

    I am able to list added records of table. But if table has any reference table. Then it will show you stored Id of reference table.

    But I want to list name field of reference table instead of Id. To make it more readable.

    Please see attached screenshot here. Please help me to get expected result. enter image description here

  • Julian 7 posts 76 karma points
    Aug 23, 2018 @ 09:56
    Julian
    0

    Hi, I'm also curious, and would like a simple solution to this, instead of having to create a custom repository (only solution i can think of) and modify the GetPaged() method for every table I have.

    Can anyone help, or shed some light on this?

  • Comment author was deleted

    Aug 23, 2018 @ 10:02

    Hey, you'll have to hook into the event model and write the select query... there should be some examples here on the forum, I'll see what I can find...

  • Comment author was deleted

    Aug 23, 2018 @ 10:04
  • Julian 7 posts 76 karma points
    Aug 23, 2018 @ 13:26
    Julian
    0

    Hi Tim, Thanks for the speedy reply. I've checked the example, and implemented the code in my project. Due to being on an older Umbraco, and MVC project, I had to reference a different object, as seen in my code;

    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            //UIOMatic.Web.Controllers.ObjectController
            UIOMatic.Services.UIOMaticObjectService.BuiltQuery += PropertyTypeListTranslations_BuildedQuery;
        }
    private void PropertyTypeListTranslations_BuildedQuery(object sender, UIOMatic.QueryEventArgs e)
        {
            if (string.Compare(
                    e.TableName, 
                    CS.Common.Constants.Enums.RemaxEntities.PropertyTypeListTranslations.ToString(), 
                    StringComparison.InvariantCultureIgnoreCase) == 0)
            {
    
                e.Query = Umbraco.Core.Persistence.Sql.Builder
                    .Append(@"SELECT propertytypelisttranslations.Id, 
                                        propertytypelisttranslations.PropertyTypeListId, 
                                        propertytypelisttranslations.LanguageId,
                                        languages.Name, 
                                        propertytypelisttranslations.Name ")
                    .Append("FROM propertytypelisttranslations ")
                    .Append("INNER JOIN languages ON languages.Id = propertytypelisttranslations.LanguageId ")
                    .Append("ORDER BY " + (string.IsNullOrEmpty(e.SortColumn) ? " Id desc" : e.SortColumn + " " + e.SortOrder));
            }
        }
    

    Every time I click to open a UI-O-Matic entity, my code hits the if loop, and enters when the correct table is clicked, and my query works (tested resulting Query in appropriate DBMS).

    However, my FK isn't being replaced with the field I'd like to return instead, which would be langauges.Name instead of propertytypelisttranslations.LanguageId

    Do I have to add something to the resulting POCO, but keep it empty?

  • Comment author was deleted

    Aug 23, 2018 @ 13:35

    Yeah you need update your poco so it includes a name property that can be populated

  • Comment author was deleted

    Aug 23, 2018 @ 13:35

    and mark it with

    [ResultColumn] [UIOMaticIgnoreField]

  • Comment author was deleted

    Aug 23, 2018 @ 13:36
  • Comment author was deleted

    Aug 23, 2018 @ 13:46

    But it seems you have 2 with the alias Name, so you'll have to have an as ... in your query

  • Julian 7 posts 76 karma points
    Aug 23, 2018 @ 14:07
    Julian
    0

    I have updated my POCO accordingly, to name them uniquely. I have also added the LanguageName to my POCO, and given it the attributes as Iyou linked;

    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
    public class UIOMaticIgnoreFieldAttribute : Attribute
    {
    }
    

    Making it;

    [ResultColumn]
        [UIOMaticIgnoreField]
        public string LanguageName { get; set; }
    

    However, my FK is still not being replaced with the new field;

    enter image description here

    Anything else I can do?

  • Comment author was deleted

    Aug 23, 2018 @ 14:14

    Which ui o matic version are you using, for an item to appear in the list view you also have to mark it with an attribute

  • Comment author was deleted

    Aug 23, 2018 @ 14:16

    so with the attri [UIOMaticListViewField]

  • Julian 7 posts 76 karma points
    Aug 23, 2018 @ 15:20
    Julian
    0

    It looks like I managed to get it working! basically what I did after changing the attribute, is move the LangaugeName next to LanguageId, and removed

    [UIOMaticListViewField(Name = "Language")]
    

    from LanguageId.

    I added what i removed, to LanguageName instead, and well, it works how I want it to be honest; enter image description here enter image description here

    My POCO for what I mean;

    [ResultColumn]
        [UIOMaticIgnoreField]
        [UIOMaticListViewField]
        public string LanguageName { get; set; }
    
        [Required]
        [UIOMaticField(Name = "Language", Description = "The language used",
            View = UIOMatic.Constants.FieldEditors.Dropdown,
            Config = "{'typeAlias': 'Languages', 'valueColumn': 'Id', 'sortColumn': 'Name', 'textTemplate' : '{{Name}}'}")]
        [Column("LanguageId")] //FK field in the table
        public int LanguageId { get; set; }
    
  • Comment author was deleted

    Aug 23, 2018 @ 14:34

    Does that do the trick? It won't replace it but will add a new column... if you wish to remove the id column then don't mark that with the attribute

  • Comment author was deleted

    Aug 23, 2018 @ 15:24

    Great, glad you have it working!

  • Dallas 133 posts 405 karma points
    Aug 18, 2021 @ 03:06
    Dallas
    0

    Is it possible to have a custom query for the edit screen in UI-O-Matic? The BuiltQuery event allows for a custom query in the List View that displays all of the records. Is there something equivalent for a single record?

    I need to access a value from a related table to display on the edit screen. It is not editable and for display only.

    Thanks

    Dallas

Please Sign in or register to post replies

Write your reply to:

Draft