This is a migrated thread and some comments may be shown as answers.
Conditional statements inside a client template.
6 Answers 306 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Brandon
Top achievements
Rank 1
Brandon asked on 26 Sep 2011, 11:50 PM
Couple issues here. I have a very simple ajax enabled grid in a view that is primarially used in a partial view. I need to conditionally change certain things in the row given certain values in the row. What I origionally came up with based on an article I found on here, was the following:

@(Html.Telerik().Grid<WTC.StatementAutomation.Model.ProcessingQueue>()
       .Name("ProcessingQueue")
       .DataBinding(dataBinding => dataBinding
           .Ajax()
               .Select("Partial", "ProcessingQueue")
       )
       .RowAction(row =>
       {
           if (row.DataItem.ProcessingQueueStatus == ProcessingQueue.QueueStatus.ReadyForAssignment)
           {
               row.HtmlAttributes["style"] = "background: url(" +
                   Url.Content("~/images/redBlend.png") +
                   ") repeat-x bottom;";
           }
       })
       .Columns(columns =>
       {
           columns.Bound(o => o.Command);
           columns.Bound(o => o.ProcessTime);
           columns.Bound(o => o.WorkType);
           columns.Bound(o => o.Server);
           columns.Bound(o => o.ProcessingQueueStatus);
           columns.Bound(o => o.Priority);
           columns.Bound(o => o.LastUpdated);
           columns.Template(
                   @<text>
                       @if (item.ProcessingQueueStatus != ProcessingQueue.QueueStatus.ReadyForAssignment)
                       {
                           @Html.ActionImage("Delete", "ProcessingQueue", new { id = item.ProcessingQueueId },
                                                   Url.Content("~/Images/control_stop_blue.png"), null)
                           @Html.ActionImage("Bump", "ProcessingQueue", new { id = item.ProcessingQueueId },
                                                   Url.Content("~/Images/bullet_arrow_top.png"), null)
                       }
                   </text>
               )
               .Width(46).Title("");
       }
       )
       .Pageable()
       .Sortable(sorting => sorting.Enabled(false))
       .Filterable(filter => filter.Enabled(false))
       .Groupable(grouping => grouping.Enabled(false))
       .Footer(false)
   )

This worked for the server side binding but does not work with ajax. My understanding on this is that  I would need to use ClientTemplate in this particular case. So I came up with the following to append to the server template:

.ClientTemplate(
    Html.ActionImage("Delete", "ProcessingQueue", new { id = "<#=ProcessingQueueId#>" }, Url.Content("~/Images/control_stop_blue.png"), null).ToHtmlString() +
    Html.ActionImage("Bump", "ProcessingQueue", new { id = "<#=ProcessingQueueId#>" }, Url.Content("~/Images/bullet_arrow_top.png"), null).ToHtmlString()
)

But I am really not understanding how to wrap if statements around that. I tried creating the whole thing as a string and doing the whole <# if (conditions) { #> thing, but the problem is I dont think this process has any awareness of the ProcessingQueue.QueueStatus.ReadyForAssignment property, because Im getting some weird javascript errors when I try to do that. Any ideas? By the way "ActionImage" is just a custom extension that I created that bascially wraps ActionLink to make an image instead.

6 Answers, 1 is accepted

Sort by
0
Brandon
Top achievements
Rank 1
answered on 27 Sep 2011, 10:36 PM
Bump... anybody home?
0
Jon
Top achievements
Rank 1
answered on 28 Sep 2011, 02:59 PM
I'm running into the same issue this morning, any luck on this?
0
Jon
Top achievements
Rank 1
answered on 28 Sep 2011, 03:05 PM
Sorry, misread your post... deleting my response.

0
Brandon
Top achievements
Rank 1
answered on 29 Sep 2011, 10:02 PM
Would be really nice if they would stick around their own forums to support their products... :-\
0
Iana Tsolova
Telerik team
answered on 03 Oct 2011, 04:08 AM
Hi Brandon,

Please post your question in the ASP.NET MVC Grid forum.
Additionally, if your case is urgent, open a formal support ticket.

Greetings,
Iana Tsolova
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Brandon
Top achievements
Rank 1
answered on 18 Oct 2011, 10:24 PM
Can you just move my thread to the other forum instead making me repost the whole thing? :-\

In any case, I figured this out. I ended up extending the model class (ProcessingQueue) to include properties for the fields I wanted to test for and then just using the <# #> method (not sure what its called) like so:

                        "<# if (AllowDelete==1) {#>" +
                        "<input type='image' src='" + @Url.Content("~/Images/control_stop_blue.png") + "' onclick='QueueAction(&quot;Delete&quot,<#= ProcessingQueueId #> )' />" +                       
                        " <#}#>" +
                        "<# if (AllowBump==1) {#>" +
                        "<input type='image' src='" + @Url.Content("~/Images/bullet_arrow_top.png") + "' onclick='QueueAction(&quot;Bump&quot,<#= ProcessingQueueId #> )' />" +
                        " <#}#>"

Kinda messy but it does the job.
Tags
Grid
Asked by
Brandon
Top achievements
Rank 1
Answers by
Brandon
Top achievements
Rank 1
Jon
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or