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

Conditional Client Template Help needed

2 Answers 103 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.
SIMC
Top achievements
Rank 1
SIMC asked on 21 Mar 2012, 09:19 PM
I've got the following basic grid definition with client template for one of the columns
@(Html.Telerik().Grid<WireInstructionWorkflowPoco>()
        .Name("Grid")
        .Columns(columns =>
        {
            columns.Bound(i => i.InstructionApprovalState).Title("Status").Filterable(false);
            columns.Bound(i => i.EntityName).Title("From");
            columns.Bound(i => i.InvestmentName).Title("To");
            columns.Bound(i => i.PositionName).Title("Position");
            columns.Bound(i => i.AsOfDateTime).Format("{0:MM/dd/yyyy}").Width(120).Title("Due Date");
            columns.Bound(i => i.InstructionsGUID).ClientTemplate(
                        @Html.ActionLink("Approve", "ApproveWireInstruction", new { instructionID = "<#=InstructionsGUID#>" }).ToHtmlString()
                                                                    ).Title("Action").Filterable(false);
        })
        .DataBinding(dataBinding => dataBinding.Ajax().Select("_AjaxBinding", "WireInstructionsPipeline"))
        .Groupable()
        .Sortable()
        .Pageable()
        .Filterable()
I need the template to be different based on a column value in the row. Let's say it'd be the previous, AsOfDateTime column. If a date is greater then 1/1/2011, I'll have one action link, otherwise, I'll have another action link. I can't figure out the syntax to make this work.
Any help? 
Thanks in advance!
Alex

2 Answers, 1 is accepted

Sort by
0
Dadv
Top achievements
Rank 1
answered on 22 Mar 2012, 10:11 AM
Hi,
in my point of view you should consider to make the logic in the action.


@(Html.Telerik().Grid<WireInstructionWorkflowPoco>()
        .Name("Grid")
   .DataKeys(c => c.Add(d => d.InstructionsGUID).RouteKey("InstructionsGUID"))
        .Columns(columns =>
        {
            columns.Bound(i => i.InstructionApprovalState).Title("Status").Filterable(false);
            columns.Bound(i => i.EntityName).Title("From");
            columns.Bound(i => i.InvestmentName).Title("To");
            columns.Bound(i => i.PositionName).Title("Position");
            columns.Bound(i => i.AsOfDateTime).Format("{0:MM/dd/yyyy}").Width(120).Title("Due Date");
            
columns.Command(c=> c.Custom("Approve").Action("ApproveWireInstruction","Controller").ButtonType(GridButtonType.Text).Text("Approve").SendDataKeys(true));
        })
        .DataBinding(dataBinding => dataBinding.Ajax().Select("_AjaxBinding", "WireInstructionsPipeline"))
        .Groupable()
        .Sortable()
        .Pageable()
        .Filterable()


And now in the ApproveWireInstruction Action:

public ActionResult ApproveWireInstruction(int instructionsGUID)
{
WireInstructionWorkflowPoco model = MyEntities.WireInstructionWorkflowPocos.FirstOrDefault(f=>f.InstructionsGUID == instructionsGUID );
if(model != null)
{
if(model.AsOfDateTime > new DateTime(2011,1,1))
{
//TODO add logic
}
else
{
//TODO add logic
}
}
throw new Exception();
}


For security purpose you need to do the validation in server side.

Nota : you could stay with your first implementation, you only have to change the server side, this is just an example of where to use Command and Datakey.
0
SIMC
Top achievements
Rank 1
answered on 04 Apr 2012, 09:49 PM
Telerik support suggested to to call a javascript function to generate client site template and it works well for the most part
.....columns.Bound(i => i.ID).ClientTemplate( "<#=getActionTemplate(ID, Status)#>")
I don't think I can do it on the serer, since one has to use clientTemplate for ajax binding.
Even though the Telerik-suggested way work, I may look at the suggested above way to generate commands on the server to see if it better suites my needs.

What took me a while to figure out is how to pass not just separate fields of a row, but the whole row data object (this time for ClientTemplate for 
DetailView).  
This is how - use data object as in:
.....columns.Bound(i => i.ID).ClientTemplate( "<#=getActionTemplate(data)#>") 


Thanks,
Tags
Grid
Asked by
SIMC
Top achievements
Rank 1
Answers by
Dadv
Top achievements
Rank 1
SIMC
Top achievements
Rank 1
Share this question
or