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

[Solved] complex expressions in columns doesn't work

2 Answers 52 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.
Manuel Vögele
Top achievements
Rank 1
Manuel Vögele asked on 12 Jan 2010, 02:56 PM
Hi!

A modification of the Telerik-CustomBinding-Example will show you what I mean with "complex expressions in columns doesn't work".

    <%= Html.Telerik().Grid(Model) 
            .Name("Grid"
            .Columns(columns => 
            { 
                columns.Add(o => o.OrderID).Width(100); 
                columns.Add(o => o.Customer.ContactName + "AppendThisString").Width(200); 
                columns.Add(o => o.ShipAddress); 
                columns.Add(o => o.OrderDate).Format("{0:MM/dd/yyyy}").Width(100); 
            }) 
            .RowAction( row => row.HtmlAttributes[ "id" ] = row.DataItem.OrderID )           
            .Ajax(settings => settings.Action("_CustomBinding""Grid")) 
            .Pageable(settings => settings.Total((int)ViewData["total"])) 
            .EnableCustomBinding(true
            .Sortable() 
    %> 

I only changed the line where the second column is defined and added "+ "AppendThisString"" to the existing lambda expression. Now it's more then a simple property. At the first look it seems to work, but if I change the page and load new data by ajax, the secound column will not execute the expression and so the old data are still shown in this column.

By the way... the same happens with the row-id-tag (calculated by the RowAction-expression). If you change the page, the id of the row is still old, too.

Any ideas?

Greetings

Manuel


2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 12 Jan 2010, 03:07 PM
Hi Manuel Vögele,

Indeed we support only simple expressions - member access only (field and property access). This means that no operators or method invocations will work. The reason is very simple - we serialize those and use them in client-side binding (ajax or web service). Our expression engine expects "Customer.ContactName" and does not know what to do with "Customer.ContactName + AppendThisTring". For example we cannot sort by this expression since there is no such property. If you just want to customize the way the data is output in the row you can use the Format property:

columns.Add(o => o.Customer.ContactName).Format("{0}AppendThisString");

The problem with the RowAction stems from the fact that those attributes are rendered server side. When performing client-side binding they are not updated. In a word there is no way to map C# code to JavaScript thus we cannot apply the RowAction on the client-side. As a workaround you can use the OnRowDataBound client-side event:

.ClientEvents(c => c.OnRowDataBound("onRowDataBound"))
        .Pageable()
        .Sortable()
        .Filterable()
%>

<script type="text/javascript">
function onRowDataBound(e) {
    e.row.id = e.dataItem.OrderID;
}
</script>

Regards,
Atanas Korchev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Manuel Vögele
Top achievements
Rank 1
answered on 12 Jan 2010, 03:24 PM
It works...

Thanks
Tags
Grid
Asked by
Manuel Vögele
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Manuel Vögele
Top achievements
Rank 1
Share this question
or