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

Conditional bound column

4 Answers 1032 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tomer
Top achievements
Rank 1
Tomer asked on 30 Jul 2012, 06:28 AM
 Hi,

I am trying to add conditional to bound column on GRID. I saw an example that you showed on conditional column in the past and it didn't help me. In my code It only entered to one conditional only. 
It is Boolean column. for example If I have two rows with one value that is: true and the other is false, I will get to true and It will not entered into the else condition.

Here is my code:

@(Html.Telerik().Grid<CRC.Models.CRC_DB_IsConnected>()

                            .Name("Grid")

                            .Columns(columns =>

                                {

                                    columns.Bound(o => o.Name).Width(200);

                                    columns.Bound(o => o.IsConnected).Width(200);

                                    columns.Bound(o => o.IsConnected).ClientTemplate("<# if( item.IsConnected == true) { #> <img width='16' height='16' alt='Connected' src='" + Url.Content("~/Content/Images/buttonCircle_blank_green.png") + "' /> <# } else {#> <img width='16' height='16' alt='Not Connected' src='" + Url.Content("~/Content/Images/buttonCircle_blank_red.png") + "' /> <# } #>").Title("Is Connected");                                   

                                   

                                })

                                .DataBinding(dataBinding => dataBinding.Ajax().Select("_AjaxBinding""Home"))

                                    .Pageable()

                                    .Sortable()

                                    .Scrollable()

                                    .Groupable()

                                    .Filterable()

                                    )

4 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 30 Jul 2012, 08:52 AM
Hello Tomer,

Looking at the code snippet you have provided there seems to be few issue with the template you have declared.

 - The template code blocks syntax is not correct. Kendo template does use #=# instead of <#=#>. More details about KendoUI template can be found in our online documentation.
 - There is no item variable in the context of the template. 

Thus, the template should look similar to the following:

"# if( IsConnected == true) { # <img ... /> # } else {# <img ... /> # } #"

Greetings,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Tomer
Top achievements
Rank 1
answered on 30 Jul 2012, 09:00 AM
.
0
Gary
Top achievements
Rank 1
answered on 01 Aug 2012, 08:52 PM
Since this took me a bit of trial and error to figure out I thought I'd share.  To do a conditional with say flagred.gif if itemCount is 0 else itemCount, the syntax is like so:   

"# if( itemCount === 0) { # <img src='images/flagred.gif' /> # } else {#<span>#:itemCount#<span>#} #"
0
Ran
Top achievements
Rank 1
answered on 05 Aug 2012, 07:06 PM
Gary thank you very much, I could barely find documentation on this. Your post has helped a lot.
Thanx again
Tags
Grid
Asked by
Tomer
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Tomer
Top achievements
Rank 1
Gary
Top achievements
Rank 1
Ran
Top achievements
Rank 1
Share this question
or