..." /> ..." /> ..."/>

What determines the type of a grid column in a Telerik MVC grid?

171 views Asked by At

My column is defined as follows:

columns.Bound(o => o.SequenceNumber).Title("Seq #").Width(50).ClientTemplate("' value='<#=SequenceNumber#>' />");

The model I'm pulling in has SequenceNumber defined as Nullable<decimal>. When I pull in the grid's properties, the Type is "Number". Normally, this is referring to integers in our program. I know that "Decimal" is a valid value for the Type. How do I get my datacolumn to show up as that Type?

2

There are 2 answers

0
Sean Duggan On BEST ANSWER

At this point, my solution is to manually change the data type for the column for this grid as it is retrieved for export, as my attempts to suggest a datatype failed.

1
Leniency On

The Telerik controls do some basic reflection to match up an appropriate editor. Nullable<decimal> doesn't appear to match the numeric editor though (tested v2015.1.318).

Instead, you'll want to provide more general attributes that it knows to check for:

// This assumes you have the editor templates added
// to your  ~/Views/Shared/EditorTemplates folder.
[UIHint("Number")]
[DisplayFormat(DataFormatString = "0.00")]
public Nullable<decimal> SequenceNumber { get; set; }

You can also use [DataType] as well for currency types.

[DataType(DataType.Currency)]
public Nullable<decimal> Amount{ get; set; }

Edit -

Tested another method by adding a new EditorTemplate called Decimal.cshtml into ~/Views/Shared/EditorTemplates:

@model decimal?
@(Html.Kendo().NumericTextBoxFor(m => m)) 

The grid finds this as expected with no additional attributes on SequenceNumber.