I have a BsGrid(...) with sortable columns.
When I click the title to reorder, its make Ajax request, I processed the data in Controller and return the correct ordered data. But grid wasn't "refreshed" with ordered data.
My code is:
public ActionResult List(BsGridBaseRepositorySettings settings)
{
var all = this._service.GetAll();
var gridItems = AutoMapper.Mapper.Map<List>(all);
if (settings.OrderableColumns[0].Type == BsOrderType.Descending)
{
gridItems = gridItems.OrderByDescending(x => settings.OrderableColumns[0].Name == "Name" ? x.Name : x.Type).ToList();
}
else
{
gridItems = gridItems.OrderBy(x => settings.OrderableColumns[0].Name == "Name" ? x.Name : x.Type).ToList();
}
return Json(new { result = gridItems });
}
Grid's code in View is:
@using (Html.BsGridWrapper())
{
@(
Html.BsGridFor(m => m.Grid)
.ConfigureColumns(cols =>
{
cols.For(x => x.Name).Name("Name");
cols.For(x => x.Date).Name("Date")
.Text(i => i.Date.DateValue.GetValueOrDefault().ToString(E_Voting.Core.Common.Formating.DateFormat));
cols.For(x => x.Type).Name("Type");
})
.PagerSettings(new BsPagerSettings
{
Size = 5,
ShowFirstLastButtons = true,
ShowPrevNextButtons = true,
HasPagesText = true,
HasPageSizeSelector = true
})
.IgnoreAjaxRequest(true)
)
}
the returned data is (when order type is ASC):
{"result":[{"ID":1,"Name":"N1 2014","Date":{"TextValue":"13.11.2014 谐. 0:00:00","DateValue":"/Date(1415829600000)/"},"Type":"E Type"},{"ID":2,"Name":"N2 2014","Date":{"TextValue":"3.12.2014 谐. 0:00:00","DateValue":"/Date(1417557600000)/"},"Type":"P Type"},{"ID":3,"Name":"N3 2014","Date":{"TextValue":"3.12.2014 谐. 0:00:00","DateValue":"/Date(1417557600000)/"},"Type":"P Type"}]}
when order is DESC:
{"result":[{"ID":2,"Name":"N2 2014","Date":{"TextValue":"3.12.2014 谐. 0:00:00","DateValue":"/Date(1417557600000)/"},"Type":"P Type"},{"ID":3,"Name":"N3 2014","Date":{"TextValue":"3.12.2014 谐. 0:00:00","DateValue":"/Date(1417557600000)/"},"Type":"P Type"},{"ID":1,"Name":"N1 2014","Date":{"TextValue":"13.11.2014 谐. 0:00:00","DateValue":"/Date(1415829600000)/"},"Type":"E Type"}]}