Copied to clipboard

Flag this post as spam?

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


  • MaryL 12 posts 44 karma points
    Jul 28, 2015 @ 01:19
    MaryL
    1

    Display Dropdown Text in List View

    I have:

    • Custom Dropdown List with alphabetical values
    • Custom List View that includes the my custom Dropdown List.

    The list view however does not show the text values. It shows the key ID. I tried both DropdownlistPublishingKeys and Dropdownlist, they both show the ID, not the text.

    How do I change this?

    enter image description here

  • Casper Andersen 126 posts 508 karma points
    Jul 28, 2015 @ 06:16
    Casper Andersen
    0

    If i understand your question correctly, then u went into the umbraco backoffice, and went to the developer section, and create a custom data type with a name and a property type of DropDownList and then added some prevalues as text. If that is the case then this code will do the trick, but in my example i am doing the code inside a controller and returning it as part of a model and then returning a PartialView with myModel values

        XPathNodeIterator iterator = umbraco.library.GetPreValues(1125);
    // 1125 is the ID of your custom datatype, you can see the ID of your 
    // custom datatype by going to it in the backend inside the developer tab
    // and checking the URL 
                    iterator.MoveNext(); //move to first
                    XPathNodeIterator preValues = iterator.Current.SelectChildren("preValue", "");
                    while (preValues.MoveNext())
                    {
                        string preValue = preValues.Current.Value;
                        int preValueId = preValues.CurrentPosition;
    
                        listBaneItems.Add(new SelectListItem
                        {
                            Text = preValue,
                            Value = preValue
                        });
                        myModel.ListeAfBaneOnsker = listBaneItems;
                    }
    
  • MaryL 12 posts 44 karma points
    Jul 29, 2015 @ 21:43
    MaryL
    0

    Hi Casper,

    Thank you very much for the info. You are absolutely correct, I did go in the backoffice, created a custom dropdown (DropX) and put in some pre-value texts in there.

    And then, I created a custom ListView (say ListX) in the backoffice again and added ListX in the list view.

    I am not entirely sure where to put the code you sent though. I looked everywhere in the umbraco backoffice for controllers, I cant find any. I looked within the actual site files (the entire application) but I cant find anything in there either. Can you please put me in the right direction as to where I should be inserting this code? I assume a file that has the ListX code. Sorry I am quite new to this so my lingo and references might be off. Thanks for your help again. Appreciate it.

  • Stuart Belcher 1 post 71 karma points
    Oct 24, 2015 @ 19:16
    Stuart Belcher
    0

    Hey guys,

    I've just come across the same problem. Really odd this isn't out the box, and even stranger the id's are the display default. Did you come up with a solution?

    @Casper - Like MaryL I'm not sure where to put your code. Can you advise?

  • Veronica Burd 76 posts 201 karma points
    Dec 09, 2015 @ 15:58
    Veronica Burd
    0

    I just found a need for this too. Anyone have any ideas? Can we somehow cleanly tap into the rendering of the listview and replace the Ids with the text equivalent?

    Thanks

  • Veronica Burd 76 posts 201 karma points
    Jan 11, 2016 @ 08:16
    Veronica Burd
    0

    Just found that this was raised as an issue by Jan Bengtsson in March 2015.

    Dropdown list in List View - a switch is needed

    So, I suggest you vote for it to show your interest.

    Regards

    Ver

  • Matthieu Nelmes 102 posts 385 karma points
    Mar 10, 2017 @ 11:38
    Matthieu Nelmes
    0

    Anyone know if there's an out-of-the-box solution for this?

    I'd rather not have to code a custom listview just to display a dropdown value...

  • Lorenzo Mercati 22 posts 45 karma points
    Apr 11, 2017 @ 10:24
    Lorenzo Mercati
    1

    Same problem.

    We need a solution.

  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Apr 11, 2017 @ 11:09
    Bjarne Fyrstenborg
    1

    It would indeed be useful to display the prevalue text instead of the prevalue id. http://issues.umbraco.org/issue/U4-6405

    Instead of creating a custom listview property editor a temporary solution might be to add a custom listview layout and optionally order it as the first listview layout.

    /Bjarne

  • Lorenzo Mercati 22 posts 45 karma points
    Apr 11, 2017 @ 14:25
    Lorenzo Mercati
    0

    Ok, thanks.

    I follow the tutorial.

    Replacing the string in the html file I have:

    <div class="my-songs-layout__myDropDownListName">{{ item.myDropDownListName }}</div>
    

    But this way I retrieve the ID of my drop down list item.

    How can I get the text?

    Thanks in advance

  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Apr 11, 2017 @ 16:10
    Bjarne Fyrstenborg
    0

    In the Angular controller, you can use that id and entityResource https://our.umbraco.org/apidocs/ui/#/api/umbraco.resources.entityResource to look-up the entity and get its name, when using MNTP.

    entityResource.getById(input, "Document")
                .then(function(ent) {
                    // name
                    item.newProperty = ent.name;
                });
    

    For dropdownlist you need to get the text from the prevalue id ... not sure if there is anything in the core for that in Angular, otherwise you can create an Angular service like this https://github.com/warrenbuckley/Analytics/blob/develop/Analytics/App_Plugins/Analytics/backOffice/AnalyticsTree/resources/Settings.Resource.js, which makes a http request to a web api method, which return the prevalue text. https://our.umbraco.org/documentation/reference/routing/webapi/

    The ApiController can inherit from UmbracoAuthorizedController ...

    private string GetPrevalue(string prevalueId)
    {
        if (!string.IsNullOrEmpty(prevalueId))
        {
            var preval = Umbraco.GetPreValueAsString(Convert.ToInt32(prevalueId));
            return preval ?? string.Empty;
        }
        return string.Empty;
    }
    

    Some other relevant resources:

    https://github.com/umco/umbraco-nested-content/blob/develop/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Js/nestedcontent.filters.js

    https://github.com/kgiszewski/ArchetypeManual/blob/master/02%20-%20Configuration.md#label-template

Please Sign in or register to post replies

Write your reply to:

Draft