Display 'Yes' instead of 'true' for Boolean values

10 posts, 1 answers
  1. Richard
    Richard avatar
    2 posts
    Member since:
    Jun 2014

    Posted 30 Jun 2014 Link to this post

    I cannot seem to find out how to do this from the documentation.

    My model has a Boolean field which displays as 'true' or 'false'.

    How can I set the grid to display as 'Yes' or 'No' respectively.

    Thanks,

    Richard
  2. Answer
    Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 30 Jun 2014 Link to this post

    Hello Richard,


    You could use a template to achieve this. Here is a sample implementation, assuming that an Ajax dataSource is used in the current case.
    E.g.
    columns.Bound(p => p.MyBool).ClientTemplate("#= MyBool ? 'Yes' : 'No' #")

    Regards,
    Dimiter Madjarov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Kathirvel
    Kathirvel avatar
    1 posts
    Member since:
    Feb 2014

    Posted 14 Jan 2015 in reply to Dimiter Madjarov Link to this post

    Hi I am using the same for an editable column and and am not able to see Yes/No in the bool column. But am able to the check box on clicking the cell(in edit mode.)

     columns.Bound(m => m.IsTrue).Title("Auto WO").Width(50).ClientTemplate("<#=IsTrue? 'Yes' : 'No' #>");

    Regards,
    Kathir
  5. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 14 Jan 2015 Link to this post

    Hello Kathir,

    The reason for the issue are the added < and > signs. The rendered template results in <no> or <yes> which is interpreted as a tag from the browser. As a solution, you could define the template the following way.
    E.g.

    columns.Bound(p => p.IsTrue).ClientTemplate("#: IsTrue ? '<Yes>' : '<No>' #")

    Note that the #: # syntax is used, which uses HTML encoding to display the values.

    Regards,
    Dimiter Madjarov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Ross
    Ross avatar
    5 posts
    Member since:
    Nov 2015

    Posted 01 Dec 2015 Link to this post

    Hi I'm trying to do this in a hierarchy grid, but any solution tried I received the message Deducible is not defined, Deducible is the bool field I' trying to display as yes or no values. 

     columns.Bound(f => f.Deducible)
        .Width(80).ClientTemplate("#: Deducible ? '<Yes>' : '<No>' #");

     and with this

     columns.Bound(f => f.Deducible)
        .Width(80).ClientTemplate("#= Deducible ? 'Yes' : 'No' #");

     

    Can you help me? In editable mode the checkbox is displayed but if the grid is not editable it doesn't work

     

  7. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 02 Dec 2015 Link to this post

    Hello Ross,

    The provided sample code is correct and is working as expected on my end. Make sure that the property name is spelled correctly in the template.

    Regards,
    Dimiter Madjarov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  8. Mikkel
    Mikkel avatar
    58 posts
    Member since:
    Aug 2012

    Posted 05 Apr in reply to Dimiter Madjarov Link to this post

    I used the same template in my grid, but when I added a sub grid using the same template, I got an error "Invalid Template".
    After hours and hours of trial and error, I finally found the solution to that problem which was to escape the template hash tags in the subgrid like this:

    columns.Bound(p => p.MyBool).ClientTemplate("\#= MyBool ? 'Yes' : 'No' \#")
  9. Cristina
    Cristina avatar
    6 posts
    Member since:
    Apr 2016

    Posted 29 Jun in reply to Dimiter Madjarov Link to this post

    I've tried this but any time I add the ClientTemplate, my view throws and an HTTP Exception citing "invalid filename for file monitoring" on the EditorTemplates folder (I'm guessing this is because there is an error with my value so it is trying to find a template file...?).  Otherwise, everything works well, I'm just trying to display my true/false as yes/no.  My grid is inside a detail template, so could this possibly be a syntax error.  Here is my detail template (the grid is ajax bound based on a report ID passed to the template):

    <script id="template" type="text/x-kendo-tmpl">
        @(Html.Kendo().Grid<RV_GroupViewModel>()
              .Name("gridReportGroup")
              .Columns(columns =>
              {
                  columns.Bound(rg => rg.IsSelected).Title("Has Access?").ClientTemplate("#= IsSelected ? 'Yes' : 'No' #");
                  columns.Bound(rg => rg.GroupName);
                  columns.Bound(rg => rg.GroupIdentity);
              })
                .ToolBar(toolbar =>
                {
                    toolbar.Save();
                })
              .Editable(editable => editable.Mode(GridEditMode.InCell))
              .HtmlAttributes(new { style = "height:200px;" })
              .DataSource(dataSource => dataSource
                  .Ajax()
                  .Batch(true)
                  .PageSize(10)
                  .Model(model =>
                  {
                      model.Id((g => g.GroupId));
                      model.Field(g => g.GroupIdentity).Editable(false);
                      model.Field(g => g.GroupName).Editable(false);
                  })
                  .Read(read => read.Action("ReportGroup_Read", "ReportViewer",new{reportId = "#=ReportId#"}))
                  .Update(update => update.Action("ReportGroup_Update", "ReportViewer", new { reportId = "#=ReportId#" })))
              .ToClientTemplate())
     
    </script>

  10. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 01 Jul Link to this post

    Hello Cristina,

    When a template is used in a detail template, the # symbols should be escaped, so that the template is skipped by the master Grid and evaluated by the child instead.
    E.g.

    columns.Bound(rg => rg.IsSelected).Title("Has Access?").ClientTemplate("\\#= IsSelected ? 'Yes' : 'No' \\#");

    Please let me know if this was the reason for the problem.

    Regards,
    Dimiter Madjarov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  11. Peter
    Peter avatar
    8 posts
    Member since:
    Mar 2016

    Posted 25 Aug in reply to Dimiter Madjarov Link to this post

    Hi, just a quick update. I'm using MVC Core 1.0 (rc1-final) in Visual Studio 2015 update 2 with Telerik Kendo.MVC 2016.1.301, and I did not have to quote the # characters:

    columns.Bound(col => col.MadeChoicePresets1IsSelected).Title(MadeChoicePresets1Title).ClientTemplate("#=MadeChoicePresets1IsSelected ? '&#x2611;' : '&#x2610;' #");
    columns.Bound(col => col.MadeChoicePresets2IsSelected).Title(MadeChoicePresets2Title).ClientTemplate("<input type='checkbox' disabled='disabled' #=MadeChoicePresets2IsSelected ? checked='checked' : '' # />");

    Don't know which version this happened or how, but man this has caused me many hours...

    In the first column above I use some Unicode characters instead of 'Yes' or 'No', just to show both techniques.

Back to Top
UI for ASP.NET MVC is VS 2017 Ready