3

Closed

DTG: output is not sort correctly

description

I am sort order issue.

I wrote 3 item in a DTG:
  • Google
  • Microsoft
  • Yahoo
Then I added another item. The new item position is the second:
  • Google
  • Apple (newest item)
  • Microsoft
  • Yahoo
When I render to webpage I obtain this order:
  • Google
  • Microsoft
  • Yahoo
  • Apple (newest item)
This is my Razor code:
    var dtgBinder = new uComponents.DataTypes.DataTypeGrid.ModelBinder();
    object objDTG;
    dtgBinder.Init(this.DocNodeId, this.DocNode.GetPropertyValue<string>(propertyAlias), out objDTG);

    var myDTG = (uComponents.DataTypes.DataTypeGrid.Model.GridRowCollection)objDTG;
    foreach (uComponents.DataTypes.DataTypeGrid.Model.GridRow gridRow in myDTG) {
        <div>@gridRow["name"].Value</div>
    }
I am using Umbraco 6.1.3 and uComponents 5.5.0
Closed Sep 5, 2013 at 3:13 PM by Azzlack
Fixed in changeset #a54aa03a74fe

comments

mkariti wrote Aug 14, 2013 at 11:18 AM

Same here....
I managed to meanwhile sort it via xdoc

barnakles wrote Aug 30, 2013 at 4:25 PM

Razor code (MVC)
var table = new GridRowCollection(Model.GetPropertyValue<string>(propertyAlias));

            foreach (var row in table)
            {
                <p>@row["contactDescription"].Value</p>
            }
Sample XML
      <contacts>
        <items>
          <item id="2" sortOrder="3">
            <contactDescription nodeName="Description" nodeType="-88">Breakdown cover (Europe)</contactDescription>
            <contactPhoneNumber nodeName="Phone Number" nodeType="-88">0800 737 5800</contactPhoneNumber>
            <contactOpeningHours nodeName="Opening Hours" nodeType="-89">Mon – Fri: 9am to 6pm
Sat – Sun: 9am to 6pm</contactOpeningHours>
          </item>
          <item id="1" sortOrder="2">
            <contactDescription nodeName="Description" nodeType="-88">Breakdown cover (RAC)</contactDescription>
            <contactPhoneNumber nodeName="Phone Number" nodeType="-88">0800 316 7816</contactPhoneNumber>
            <contactOpeningHours nodeName="Opening Hours" nodeType="-89">Everyday, 24 hours</contactOpeningHours>
          </item>
          <item id="3" sortOrder="1">
            <contactDescription nodeName="Description" nodeType="-88">Breakdown cover (Motoring Abroad Europe)</contactDescription>
            <contactPhoneNumber nodeName="Phone Number" nodeType="-88">0044 870 737 5700</contactPhoneNumber>
            <contactOpeningHours nodeName="Opening Hours" nodeType="-89">Everyday, 24 hours</contactOpeningHours>
          </item>
        </items>
      </contacts>
This works fine but re-orderingt the items in the grid in Umbraco does not reorder the nodes in umbrco.config and does not reorder the outputted list. Maybe there is a workaround e.g.

var table = new GridRowCollection(Model.GetPropertyValue<string>(propertyAlias)).OrderBy(x => x.SortOrder) ?

barnakles wrote Aug 30, 2013 at 4:30 PM

Haha the usual thing happened when you log an issue just to discover the workaround:
var sortedList = table.OrderBy(x => x.SortOrder).ToList();