This is a migrated thread and some comments may be shown as answers.

[Solved] Order of records not correct after ajax binding

2 Answers 18 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
John
Top achievements
Rank 1
John asked on 17 Oct 2011, 12:23 AM
Hi

I am binding a list of records to a grid with Ajax.  My service that returns the list is using custom business logic to order the records and I have not applied any sorting on the grid itself.  The problem is that the order of the records when they are bound to the grid are seemilngly randong ie they are different to the order when I view the list in the watch window of the controller while in debug mode.

Anyone else experience this?  Anyone know why?

Here is the grid in the view, and the controller action

@{ Html.Telerik().Grid<Swap>()
          .DataBinding(x => x.Ajax().Select("GetMappedSwaps", "Bond", new { bondId = Model.Id }))                           
          .Name("MappedSwapsGrid")
          .Scrollable(x => x.Height(100))
          .Footer(false)
          .Columns(columns =>
          {
              columns.Bound(o => o.SourceSystemID).Title("Calypso Ref Id").Width(120);
              columns.Bound(o => o.TradeDate).Format("{0:dd-MMM-yyyy}").Width(120);
              columns.Bound(o => o.StartDate).Format("{0:dd-MMM-yyyy}").Width(120);
              columns.Bound(o => o.MaturityDate).Format("{0:dd-MMM-yyyy}").Width(120);
              columns.Bound(o => o.Leg1Currency).Width(120);
              columns.Bound(o => o.Leg1CurrencyAmount).Width(180);
              columns.Bound(o => o.Leg1Frequency).Width(120);
              columns.Bound(o => o.Leg1FixedInterestRate).Width(180);
              columns.Bound(o => o.Leg1FloatingRateMargin).Width(180);
              columns.Bound(o => o.Leg1FloatingIndex).Width(160);
              columns.Bound(o => o.Leg2ReceiverShortName).Width(180);
              columns.Bound(o => o.Leg2InterestType).Width(140);
              columns.Bound(o => o.Leg2Currency).Width(120);
              columns.Bound(o => o.Leg2CurrencyAmount).Width(180);
              columns.Bound(o => o.Leg2Frequency).Width(120);
              columns.Bound(o => o.Leg2FixedInterestRate).Width(180);
              columns.Bound(o => o.Leg2FloatingRateMargin).Width(180);
              columns.Bound(o => o.Leg2FloatingIndex).Width(160);
          })
          .Render();
      }
[GridAction]
public ActionResult GetMappedSwaps(long bondId)
{
    var swaps = _swapService.GetMappedSwapsForBond(bondId);
    return View(new GridModel(swaps));
}

2 Answers, 1 is accepted

Sort by
0
John
Top achievements
Rank 1
answered on 25 Oct 2011, 05:17 AM
Is anyone able to help with my issue?
0
John
Top achievements
Rank 1
answered on 28 Oct 2011, 03:44 AM
I figured out a solution so I thought I would post for the benefit of anyone else having the same issue.

My IEnumerable collection was being sorted by a child record property, not by a property directly on the model.  The grid wasn't respecting the custom order of the records.  But if I cast the IEnumerable to a List in the GridModel returned, then it works.
[GridAction]
public ActionResult MappedSwapList(long bondId)
{
    return View(new GridModel(_swapService.GetMappedSwapsForBond(bondId).ToList()));
}
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
Share this question
or