I have FormTemplate class in my project
public class FormTemplate : BaseEntity
{
public virtual string Name { get; set; }
public virtual DateTime? DateCreation { get; set; }
public virtual FormTemplateGroup Group { get; set; }
public virtual bool Active { get; set; }
public virtual FormTemplateStatus Status { get; set; }
public virtual IList<QuestionBlock> QuestionBlocks { get; set; }
public virtual bool IsFreeze { get; set; }
}
and I use MVC jqGrid http://mvcjqgrid.skaele.it/Home/Formatters
to show the list of FormTemplates on the page
@(Html.Grid("Grid")
.SetCaption("List")
.AddColumn(new Column("Name").SetLabel("Name"))
.AddColumn(new Column("GroupFor").SetLabel("Group"))
.AddColumn(new Column("DateCreation").SetLabel("Date"))
.AddColumn(new Column("Status").SetLabel("Status")).SetSortOnHeaderClick(false)
.AddColumn(new Column("Id").SetLabel(" ").SetCustomFormatter("buttonize").SetWidth(220).SetAlign(Align.Center))
.SetAutoWidth(false)
.SetRowNumbers(true)
.SetUrl(Url.Action("FormTemplateGridData"))
.SetAutoWidth(true)
.SetRowNum(10)
.SetRowList(new[] { 5, 10, 15, 20 })
.SetViewRecords(true)
.SetPager("Pager"))
I don't show value of IsFreeze
property on my page, but I need to add Activate button if IsFreeze == true
and Deactivate button otherwise for every FormTemplate.
I tried to add the checking function in buttonize
function buttonize(cellvalue, options, rowobject) {
var result = '<input type="button" value="Edit" onclick="editTemplate(' + options.rowId + ')">' + ' '
+ '<input type="button" value="Delete" onclick="deleteTemplate(' + options.rowId + ')">' + ' ';
if (isFreezeTemplate(rowobject[4])) {
result += '<input type="button" value="Activate" onclick="activateTemplate(' + options.rowId + ')">';
}
else {
result += '<input type="button" value="Deativate" onclick="deactivateTemplate(' + options.rowId + ')">';
}
return result;
}
added function
function isFreezeTemplate(id) {
var check = $.post('@Url.Action("IsFreezeFormTemplate")', { id: id });
return check;
}
and added in controller
[HttpPost]
public bool IsFreezeFormTemplate(int id)
{
var formTemplate =
FormTemplateRepository.Query()
.Where(ft => ft.Id == id)
.SingleOrDefault();
if (formTemplate.IsFreeze == true) return true;
return false;
}
but I get only Activate buttons for all FormTemplates on my page.
How to fix it?