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

Sort/Filter dilemma: Bound columns require a field or property access expression

4 Answers 179 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.
Derek Hunziker
Top achievements
Rank 1
Derek Hunziker asked on 13 Aug 2010, 06:42 PM
Hi there,

I'm trying to display an IEnumerable<string> in a grid. As far as I can tell, this is impossible to achieve with sorting and filtering. Is that correct?

When I try to bind the grid I get the error: Bound columns require a field or property access expression

<% Html.Telerik().Grid(Model.Roles)
           .Name("grid")
           .Columns(col =>
           {
               col.Bound(role => role.ToString()).Template(role =>
               {
               %>
                   <%= Html.ActionLink(role, "details", new { id = role }) %>
               <%
               }).Title("Role Name");
                .Pageable()
                .Sortable()
                .Filterable()
                .Render();
%>

The easy way to fix it would be to use a simple Template, but in order to get paging and sorting, I must have the Bound() part.

Please help!

4 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 16 Aug 2010, 07:28 AM
Hi Derek Hunziker,

Indeed we don't currently support this scenario. I have logged it for further investigation. If possible we would fix it for the next official release.

Kind regards,

Atanas Korchev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
aendenne
Top achievements
Rank 1
answered on 03 Jan 2011, 09:37 PM
I just upgraded and was able to use a combination of Bound() and Template() in order to use both the ActionLink and the Format or Filterable property setters. Grid displays fine now. I sent the following to my team in order to help them along in the switch. I tested each item and my new code snippets do work. The last item (iii) includes both Bound() and Template() and uses ActionLink and sets the Filterable property for that column.

The .Add() method in the Grid control is no longer used, instead of Add use Bound(), Template() or a combo of both:

                                                               i.      Bound() example (use if Filterable or Format is required for the column, as Template does not allow those properties to be set):

//OLD WAY, USING Add():

columns.Add(o => o.CreatedDate).Format("{0:MM/dd/yyyy}").Width(40).Title("Date");

//NEW WAY, USING Template():

columns.Bound(o => o.CreatedDate).Format("{0:MM/dd/yyyy}").Width(40).Title("Date");

 

                                                             ii.      Template() example (can use if straight forward column declaration is needed, with no additional properties such as Filterable or Format):

//OLD WAY, USING Add():

columns.Add(p => Html.ActionLink("Impersonate", "SetUser", new {emplId= p.EMPLID})).Width(100);

//NEW WAY, USING Template():

columns.Template(emp => Html.ActionLink("Impersonate", "SetUser", new {emplId = emp.EMPLID})).Width(100);                        

 

                                                            iii.      Both methods example (use when Bound is necessary in order to set Filterable or Format, but when an Html helper method is also needed, such as ActionLink):

//OLD WAY, USING Add():

columns.Add(o => Html.ActionLink("View", "Details", "Award", new { id = o.AwardId }, ""))

.Width(10).Title("Action").Filterable(false);

//NEW WAY, USING Bound() AND Template():

columns.Bound(o => o.AwardId)

                           .Template(o => Html.ActionLink("View", "Details", "Award", new { id = o.AwardId }, ""))

                           .Width(10).Title("Action").Filterable(false);

 

0
Michael
Top achievements
Rank 1
answered on 15 Sep 2011, 10:33 PM
I'm having a problem with .Bound() and .Template() on the same property.

Here's my grid's columns definitions:
.Columns(columns =>
        {
// this column (bool) displays, and is both filterable and sortable.
            columns.Bound(rf => rf.locked).Title("Locked").Width(23)
                .Template( item => Html.JQGridActionIconButton( ... snip ... )
                        );
// this column (string) displays, but is not sortable or filterable
            columns.Bound(rf => rf.filename).Template(@<text>
                @(Html.ActionLink(item.filename, "ViewFile", null, new { id = item.fullpathNoPrefix }, null)) 
                @(Html.ActionLink("(download)", "DownloadFile", null, new { id = item.fullpathNoPrefix }, null))
            </text>).Title("File Name").Width(200);
            columns.Bound(rf => rf.description).Width(200).Title("Description");
// this column (int) doesn't work (the column doesn't appear in the grid at all)
            columns.Bound(rf => rf.size).Template(rf => string.Format("{0:###,###}", rf.size)).Width(50).Title("Size");
// this line works, but column isn't sortable
           
columns.Template(rf => string.Format("{0:###,###}", rf.size)).Width(50).Title("Size");
// this column (string) displays just fine
            columns.Bound(rf => rf.mime_type.description).Width(200).Title("File Type (mime-type)");
// this column (DateTime) doesn't work (column doesn't appear in grid)
            columns.Bound(rf => rf.create_date).Template(rf => rf.create_date.ToString()).Width(100).Title("Modify Date");
// ..nor does this one (nullable DateTime)
            columns.Bound(rf=>rf.expires).Template(rf => rf.expires ? rf.expire_date.ToString() : "Never" ).Width(100).Title("Expire Date");
// If I remove the .Bound(...) in the expressions above and just use the Template(), the columns
// appear, but are not filterable/sortable
            columns.Command( rf => rf.Delete().ButtonType(GridButtonType.Image)).Width(40);
        })

Any ideas?  The bound object, is an EF1 generated class.

-- pryankster
0
Alden
Top achievements
Rank 1
answered on 04 Oct 2011, 06:12 PM
I believe I am having a similar issue.

I have a column bound like this:

c.Bound(o => o.StatusId).Template(o => o.Status.Name);

There are various statuses in a table in the db, like "Active," "Inactive," etc.  But I need to bind to the key in that table, which is the StatusId.  I have edit and display templates that deal with displaying a dropdown box to choose the status on editing, and the template deals with displaying the status name to the user, not the StatusId.

The problem is with filtering.  The filters are being applied to the StatusId, which is useless to the user.  They need to be applied to the Status.Name in the template.

How do I bind to the StatusId (int), but filter on the Name (string)?
Tags
Grid
Asked by
Derek Hunziker
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
aendenne
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Alden
Top achievements
Rank 1
Share this question
or