telerikformattingconditional-statementsclient-templates

How to set font-weight of a column text to bold based on another column value in Telerik Grid


I have a Telerik grid in which based on whether my IsTrue value is true or false, I need to set the font-weight of Name text in only that particular row to bold. I tried the following but I seem to be missing something.

columns.Bound(d => d.IsTrue).Width(0).HtmlAttributes(new { id="hdnIsTrue", style = "visibility:hidden;" });
columns.Bound(d => d.Name).ClientTemplate("#<#= hdnIsTrue ? font-weight : bold : font-weight : normal #>#" + "# } #")
                            .Title("Name").Width(200);

Solution

  • I modified my code to the following with help from the post: Telerik MVC Grid making a Column Red Color based on Other Column Value

    .Columns(columns =>
             {columns.Bound(d => d.IsTrue).Width(0);
              columns.Bound(d => d.Name).Title("Name).Width(200).HtmlAttributes(new { style = "font-weight:normal;" });
    
    }).CellAction(cell => {
                            if (cell.Column.Title == "Name"){
                                  var item = cell.DataItem;
                                  if(item.IsTrue) {
                                      cell.HtmlAttributes["style"] = "font-weight : bold;";
                                  }}}).Render();