Copied to clipboard

Flag this post as spam?

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


  • Andrej Farkaš 9 posts 99 karma points
    Sep 07, 2018 @ 14:44
    Andrej Farkaš
    0

    Sorting Fludity entities

    Hi, I'm using Fluidity Entity Picker to select some speakers to show in slider. However, they are sorted by Name and not by specified order in picker.

    I'm getting a property like this:

    Model.Content.GetPropertyValue<IEnumerable<object>>("speakersInSlider").Cast<Speaker>()
    

    Thanks for any help. Should I do it differently?

  • Andrej Farkaš 9 posts 99 karma points
    Sep 11, 2018 @ 08:33
    Andrej Farkaš
    100

    It looks like there is a bug in Fluidity but you can preserve desired order by sorting it like this.

    var property = Model.Content.GetProperty(alias);
    var desiredOrder = property.DataValue.ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x));
    var data = property.GetValue<IEnumerable<object>>().Cast<FluidityModel>();
    var orderedData data.OrderBy(item => desiredOrder.IndexOf(item.Id)).ToList();
    

    For production use you should of course write this in a nicer way.

Please Sign in or register to post replies

Write your reply to:

Draft