Pregunta

Is it possible to format a Boolean to string in a Telerik Grid?

I need to change the value of a Boolean (true/false) to string (Yes/No).

My model:

[DataMember]
[DisplayName("PANDORA")]
public bool SeVePandora { get; set; }
[DataMember]
[DisplayName("PORTOS")]
public bool SeVePortos { get; set; }
[DataMember]
[DisplayName("CARRIER")]
public bool SeVeCarrier { get; set; }
[DataMember]
[DisplayName("CALCULADORA")]
public bool SeVeCalculadora { get; set; }
[DataMember]
[DisplayName("CONTROL STOCK")]
public bool SeVeControlStock { get; set; }
[DataMember]
[DisplayName("REMARKETING")]
public bool SeVeRemarketing { get; set; }
[DataMember]
[DisplayName("AUTO CREDIT")]
public bool SeVeAutocredit { get; set; }
[DataMember]
[DisplayName("VALORES RESIDUALES")]
public bool SeVeValoresResiduales { get; set; }
[DataMember]
[DisplayName("PRUEBAS")]
public bool EntornoPruebas { get; set; }

My View:

<%= Html.Telerik().Grid<VWIS.DataModels.Models.AvisosPromociones.Avisos>()
.Name("ListAvisos")
.Columns(columna =>
    {
        columna.Bound(d => d.IdAViso).Visible(false).Sortable(false);
        columna.Bound(d => d.Titulo).Width(380).Sortable(false);
        columna.Bound(d => d.FechaInicio).Format("{0:dd/MM/yyyy}").Width(95).Sortable(true);
        columna.Bound(d => d.FechaFin).Format("{0:dd/MM/yyyy}").Width(86).Sortable(true);
        columna.Bound(d => d.SeVePandora).Width(50).Sortable(false);
        columna.Bound(d => d.SeVePortos).Width(50).Sortable(false);
        columna.Bound(d => d.EntornoPruebas).Width(50).Sortable(false);
        columna.Bound(d => d.SeVeCarrier).Width(50).Sortable(false);
        columna.Bound(d => d.SeVeCalculadora).Width(50).Sortable(false);
        columna.Bound(d => d.SeVeControlStock).Width(50).Sortable(false);
        columna.Bound(d => d.SeVeRemarketing).Width(50).Sortable(false);
        columna.Bound(d => d.SeVeAutocredit).Width(50).Sortable(false);
        columna.Bound(d => d.SeVeValoresResiduales).Width(50).Sortable(false);
        }).DataBinding(datos => datos.Ajax().Select("_BusquedaAvisos", "Avisos", new { PrimeraBusqueda = true }))
                   .Pageable(page => page.PageSize(10))
                   .Selectable()
                   .Sortable()
                   .Reorderable(reorder => reorder.Columns(true))
                   .ClientEvents(e => e.OnDataBinding("OnDataBinding").OnRowSelect("SeleccionarFila"))

%>

In columna.Bound(d => d.SeVePandora).Format() lambda expresions are not allowed.

Can someone help me?

¿Fue útil?

Solución 2

I modified your code @jayesh-goyani. Telerik Grid needs a '<' to open logic in

.ClientTemplate

`colums.Bound(d => d.SeVePandora).Width(50).Sortable(false).ClientTemplate(
    "<# if (SeVePandora == true) { #>" +
        "<span>Yes</span>" +
    "<# } else { #>" +
        "<span>No</span>" +
    "<# } #>"
);`

Thank you for your help!

Otros consejos

Please try with the below code snippet.

colums.Bound(d => d.SeVePandora).Width(50).Sortable(false).ClientTemplate(
    "# if (SeVePandora == true) { #" +
        "<span>Yes</span>" +
    "# } else { #" +
        "<span>No</span>" +
    "# } #"
);

For more information please this link.

Only Client Template can be even simpler as bellow.

columns.Bound(c => c.Required).Width(65)
    .ClientTemplate("#= Price > 0 ? Required ? 'Yes' : 'No' : 'N/A'#");

In my example I check two things if price is more then zero and if required as I have three options.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top