The following is what I’m trying to do, but breaks columns sorting and ordering
In the controller
var records = _service.GetRecords().Select(s => new
{
RecordId = ...,
...
NestedListDescr = s.NestedList!.Count == 0 ? null : s.NestedList.Select(sl => sl.Description).Distinct().Take(3)
});
return Json(await DataSourceLoader.LoadAsync(records, loadOptions, cancellationToken));
In the view
@(Html.DevExtreme().DataGrid<ViewModel>().ID("grid")
.DataSource(d => d.Mvc().Controller("Home").LoadAction("GetRecords").Key("RecordId"))
.SearchPanel(s => s.Visible(true).SearchVisibleColumnsOnly(true).HighlightSearchText(true))
.ColumnHidingEnabled(true)
.RemoteOperations(true)
.Paging(page => page.PageSize(40))
.StateStoring(state => state
.Enabled(true)
.Type(StateStoringType.LocalStorage)
.StorageKey("storageKey"))
.Columns(columns =>
{
...
columns.AddFor(m => m.NestedListDescr![0]).Caption("NestedList 1").DataType(GridColumnDataType.String);
columns.AddFor(m => m.NestedListDescr![1]).Caption("NestedList 2").DataType(GridColumnDataType.String);
columns.AddFor(m => m.NestedListDescr![2]).Caption("NestedList 3").DataType(GridColumnDataType.String);
}))
I tried the below approach, which solved the sorting and ordering issue but it creates a much more complicated query in DB, which might cause loading issues when more columns or data have to be loaded in the future.
NestedListDescr1 = s.NestedList.Select(....).FirstOrDefault(),
NestedListDescr2 = s.NestedList.Select(....).Skip(1).FirstOrDefault(),
NestedListDescr2 = s.NestedList.Select(....).Skip(2).FirstOrDefault()
with
columns.AddFor(m => m.NestedListDescr1).Caption("NestedList 1").DataType(GridColumnDataType.String);
columns.AddFor(m => m.NestedListDescr2).Caption("NestedList 2").DataType(GridColumnDataType.String);
columns.AddFor(m => m.NestedListDescr3).Caption("NestedList 3").DataType(GridColumnDataType.String);
is there any other way to implement the above?
New contributor
Neoharry is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.