This is a migrated thread and some comments may be shown as answers.

Hide the number 0 in the data grid when formatted as number

1 Answer 896 Views
Grid
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 30 Sep 2013, 01:43 PM
I have a datagrid of numbers that I format as a number, but if the number if 0 or null, I want don't want anything displayed.

How do I do this with KendoUI?

Also is there an easier way to make all numbers align to the right rather than injecting a style for the column?

Here is the grid that I am using:

@(Html.Kendo().Grid<KendoWithChart.Models.Report_Result>()
            .Name("grid")
            .BindTo((IEnumerable<KendoWithChart.Models.Report_Result>)ViewBag.SomeData)
      
            .Columns(columns =>
            {
                columns.Bound(p => p.DESCRIPTION).Title("Description").ClientTemplate("# if( DESCRIPTION == 'Total IP') { # <strong>#: DESCRIPTION#</strong> # } else if( DESCRIPTION == 'Target Blended Liability') { # <strong>#: DESCRIPTION #</strong> # } else { # #: DESCRIPTION # # } #");
                columns.Bound(p => p.DV01).Format("{0:n}").HtmlAttributes(new { style = "text-align:right" });
            })
      
            
            .Sortable() // Enable sorting
            .DataSource(dataSource => dataSource.Ajax()
                .Group(group => group.Add(p => p.Type))
                .ServerOperation(false)
                
            )
        )

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 30 Sep 2013, 02:38 PM
Hi William,

 You can set the ClientTemplate of the column to do this:

columns.Bound(p => p.DV01)
         .ClientTemplate("# if (DV01) { #  #= kendo.toString(DV01, '{0:n}') #  # } #")
         .HtmlAttributes(new { style = "text-align:right" }).

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
William
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or