I have had to admit defeat after much googling and trial and error I have been unable to recreat what I want.
I have a view model that can be simplified as follows;
public class HeadsOfClaim
{
public HeadsOfClaim()
{
}
public int? ClaimId { get; set; }
public int? ClaimDetailId { get; set; }
public string ClaimType { get; set; }
public string Description { get; set; }
public bool Rejected { get; set; }
}
A controller which returns the json
public ActionResult ReturnHeads([DataSourceRequest]DataSourceRequest request, int? id)
{
Claim c = db.Claims.Find(id);
IEnumerable<HeadsOfClaim> details = ViewModels.HeadsOfClaim.GetList(c);
return Json(details.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
and a view that includes the following
@(Html.Kendo().Grid<ClaimRegister.ViewModels.HeadsOfClaim>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.ClaimType).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains").SuggestionOperator(FilterType.Contains)));
columns.Bound(p => p.Description).Filterable(ftb => ftb.Cell(cell => cell.ShowOperators(false))).Width(225);
columns.Template(@<text></text>).HtmlAttributes(new { @class = "templateCell", id = "#=id#" }).ClientTemplate(
Html.Kendo().DropDownButton()
.Name("menu_TEST_#=id#")
.Text("Action")
.Size(ComponentSize.Large)
.Items(its =>
{
its.Add().Text("Reverse Rejection").Hidden("#=Rejected#" == "true").HtmlAttributes(new { data_id = "#=id#" }).Click("ConfirmUnReject");
its.Add().Text("--Set").Hidden("#=Rejected#" != "true").Enabled(false);
its.Add().Text("Reserve").Hidden("#=Rejected#" != "true").HtmlAttributes(new { data_title = "Set Reserve", data_url = Url.Action("Individual", "Reserve", new { type = type, id = "#=id#" }) }).Click("LaunchModal");
its.Add().Text("Settlement").Hidden("#=Rejected#" != "true").HtmlAttributes(new { data_title = "Set Settlement", data_url = Url.Action("Individual", "Settlement", new { type = type, id = "#=id#" }) }).Click("LaunchModal");
its.Add().Text("--View").Enabled(false);
its.Add().Text("Allocation").HtmlAttributes(new { data_title = "Review Allocation", data_url = Url.Action("Review", "Allocation", new { id = "#=id#" }) }).Click("LaunchModal");
})
.ToClientTemplate().ToHtmlString()
);
})
.Pageable()
.Sortable()
.Groupable()
.Events(ev => ev.DataBound("initMenu"))
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
.DataSource(dataSource => dataSource
.Ajax()
.Model(m => {
m.Id(d => d.ClaimDetailId);
m.Field(d => d.Rejected);
})
.Group(groups => groups.Add(p => p.ClaimType))
.Read(read => read.Action("ReturnHeads", "ClaimDetails", new { id = id }))
)
)
...
<script>
function initMenu(e) {
$(".templateCell").each(function () {
eval($(this).children("script").last().html());
});
}
</script>
My problem is setting the visibility of the dropdown options. Effectively dependent on whether the claim is Rejected (true or false) I want different options to be available to the user.
I had a look at the template script before initMenu runs but the evaluation is already made by that stage so it is unclear how it is doing the checking.
Irrelevant of whether rejected is true or false I get "Reverse Rejection", "--View" and "Allocation" as the only visible option.
Any help or insights gratefully received.