There are several topics on this forum regarding linking Grid columns to Dictionary properties. I've managed to do just that, but these columns are missing sorting and dropdown menu.
My model represents an issue from issue tracking system that may have very different fields depending on particular configuration. I can't see it feasible to define each possible property for my model class and the only logical solution is to have direct properties for most common fields and have a Dictionary for custom fields.
I'm using Kendo.MVC version 2016.1.112 in MVC 6 / .NET 5 project (which currently doesn't support server-side binding as far as I understand - rendering some solutions posted on this forum inapplicable). Browser is Chrome, but it doesn't seem the issue relates to browser version.
My model class is as follows:
public
class
Issue
{
public
string
Key {
get
;
set
; }
public
string
Summary {
get
;
set
; }
public
string
Status {
get
;
set
; }
public
string
StatusType {
get
;
set
; }
public
DateTime? Created {
get
;
set
; }
public
DateTime? LastUpdated {
get
;
set
; }
public
Dictionary<
string
,
object
> CustomProperties {
get
;
set
; } =
new
Dictionary<
string
,
object
>();
}
The Grid is then defined in View's *.cshtml file as this:
@(Html.Kendo().Grid<JIRAReports.Models.Issue>()
.Name(
"grid"
)
.HtmlAttributes(
new
{ style =
"margin-top: 10px;"
})
.DataSource(dataSource => dataSource.Ajax()
.Sort(sort => sort.Add(
"LastUpdated"
).Ascending())
.Read(read => read.Action(
"JiraIssues_Read"
,
"Reports"
))
.PageSize(15)
)
.Columns(columns =>
{
columns.Bound(issue => issue.Key).Width(120).HtmlAttributes(
new
{ style =
"white-space: nowrap;"
})
.ClientTemplate($
"<a href=\"{baseIssueUrl}#=Key#\" target=\"_blank\">#=Key#</a>"
);
columns.Bound(issue => issue.Status).Width(150)
.ClientTemplate(statusColumnTemplate);
columns.Bound(issue => issue.Summary).HtmlAttributes(
new
{ style =
"white-space: nowrap;"
});
columns.Bound(issue => issue.LastUpdated).Width(180).HtmlAttributes(
new
{ style =
"white-space: nowrap;"
})
.Title(
"Last Updated"
).Format(
"{0:M/d/yyyy (ddd)}"
);
//Adding custom properties
columns.Template(
"#:CustomProperties['CustomProperty1']#"
).Title(
"Custom Property 1"
);
columns.Template(
"#:CustomProperties['CustomProperty2']#"
).Title(
"Custom Property 2"
).Hidden();
})
.Pageable(config => config.PageSizes(
new
[] { 10, 15, 25, 100 })
.Refresh(
true
))
.Sortable(config => config.AllowUnsort(
false
).SortMode(GridSortMode.MultipleColumn))
.Scrollable(config => config.Height(
"895px"
))
.Resizable(config => config.Columns(
true
))
.ClientDetailTemplateId(
"item-template"
)
.ToolBar(tools => tools.Custom().Text(
"Expand All"
).Name(
"ExpandAll"
))
.ToolBar(tools => tools.Custom().Text(
"Collapse All"
).Name(
"CollapseAll"
))
.NoRecords()
.ColumnMenu()
.Reorderable(config => config.Columns(
true
))
.Deferred()
The resulting grid is rendered as on the screenshot attached. You can see there is no dropdown next to columns linked to Dictionary's items, they are not sortable, but these columns do appear in dropdowns for other columns so they can be shown/hidden. But sorting on them is absolutely required.
Please suggest a solution. There must be a way to link to less structured data or indexer property, especially since all we need is to display it in read-only mode.