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

How to display List<object> Count in a cell

1 Answer 910 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 2
Andrew asked on 09 Oct 2016, 07:49 PM

In a simple table, I know I'd be able to just call Count in a cell, and there weren't any problems. However, trying to do it in a Grid has been challenging:

This is how my MVC Grid looks like:

@(Html.Kendo().Grid<ContentExternalLink>()
            .Name("issue-grid")
            .DataSource(dataSource => dataSource
            .Ajax()
            .Model(model => model.Id(x => x.LinkId))
            .Read(read => read.Action("ContentExternalLink_Read", "ContentManagement"))
            .Create(create => create.Action("ContentExternalLink_Create", "ContentManagement"))
            .Update(update => update.Action("ContentExternalLink_Update", "ContentManagement"))
            .Destroy(delete => delete.Action("ContentExternalLink_Destroy", "ContentManagement"))
            .ServerOperation(true)
            .PageSize(10))
            .Columns(columns =>
            {
                columns.Bound(x => x.LinkId).Hidden();
                columns.Bound(x => x.LinkTitle).Title("Title").Template(@<text>
                    <a href="@item.LinkUrl" taget="_blank">@item.LinkTitle</a>
                        </text>);
                columns.Bound(x => x.LinkTypeId).Title("Type");
                columns.Bound(x => x.LinkCreatedDate).Title("Created");
                columns.Bound(x => x.ContentTagAssignments.Count).Title("Tags");
                columns.Bound(x => x.LinkSource).Hidden();
                columns.Bound(x => x.LinkPhoneNumber).Hidden();
                columns.Bound(x => x.LinkDate).Hidden();
                columns.Bound(x => x.LinkCreatedDate).Hidden();
                columns.Bound(x => x.LinkModifiedDate).Hidden();
                columns.Command(command => { command.Edit(); command.Destroy(); }).Width(250);
            })
            .ToolBar(toolbar => toolbar.Create())
            .Editable(editable => editable.Mode(GridEditMode.InLine))
            .Scrollable(scr => scr.Height("auto"))
            .Sortable()
            .Pageable(pageable => pageable
                .Refresh(true)
                .PageSizes(true)
                .ButtonCount(5))
)

When I run that, I get the Javascript error: Cannot read property 'Count' of undefined.

Any ideas how to get what I want to achieve?

Thank you!
AJ

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 11 Oct 2016, 12:01 PM
Hi Andrew,

Note that the DataSource is designed to work with flat data. If you would like to show count in one of the Grid columns you can update the Model to include a field that would hold the count value. You can populate that field in the Controller when querying the data from the database. Then , you can show that field as a separate column in the Grid component.

columns.Bound(x => x.ContentTagAssignmentsCount).Title("Tags");

On a side note, have in mind that when using Ajax binding you should use ClientTemplate for the columns. Please check out the following article that describes the approach in more detail.




Regards,
Viktor Tachev
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Andrew
Top achievements
Rank 2
Answers by
Viktor Tachev
Telerik team
Share this question
or