Layer Sorting Back-End

Topics: Administration, Customizing Orchard
Aug 25, 2011 at 12:28 PM

Ok i assume this is a relativly unimportant thing, and it can probably be easily solved, if i'd knew what i need to look for...

My "problem" is the Layeroverview in the Dashboard.

The Layer DropDownBox - i assume it's sorted by ID ( or not sorted at all, but since it gets the list from the table, it's is "sorted" by ID )

Anyway, the file i probably have to alter should be Modules\Orchard.Widgets\Views\WidgetLayersControl.cshtml

                <select id="layerId" name="layerId">
                    @foreach (var layer in layers) {
                        @Html.SelectOption((int)Model.CurrentLayer.Id, (int)layer.Id, (string)layer.Name)

what i would love that to do is sort the layers by Name from A - Z . As i have a rather sorting Namegiving for Layers it'd be way more overviewable if they were sorted by that.

However OrderBy doesn't seem to work or i did it wrong.. Does anyone have a quick solution for this?


Aug 25, 2011 at 7:16 PM

Can you show what you tried?

Aug 25, 2011 at 8:57 PM

@CoReTeX I just tried it and it works for me ...

@foreach (var layer in layers.OrderBy(l => l.Name)) {
    @Html.SelectOption((int)Model.CurrentLayer.Id, (int)layer.Id, (string)layer.Name)

You also need to add a using statement for Linq to the top of the file ...

@using System.Linq;
Doing that results in the layers being ordered alphabetically in the dropdown for me.

Aug 25, 2011 at 9:01 PM

Submit a patch! :)

Aug 25, 2011 at 9:15 PM

oh man..

i tried about that

@foreach (var layer in layers) {
@Html.SelectOption((int)Model.CurrentLayer.Id, (int)layer.Id, (string)layer.Name, OrderBy(Name))

still new to , sql and whatever else i use right now... ^^

well, always something to learn.. thanks kevink, that'll make it easier.

Aug 26, 2011 at 7:26 AM