How can I specify a format for a grid column

4 Answers 12306 Views
Grid
Patrick Rioux
Top achievements
Rank 1
Patrick Rioux asked on 24 Feb 2012, 09:00 PM
Hi,
I tried different things and nothing works.
I have a numeric column in a grid and this numeric field has no decimal.
When I filter on this column and key a value, when I change the focus to another control the field is formatted with two decimals.
How can I leave the column numeric but control the column format.

Thank you.

columns: [{field:"SalesrepId",title:"Salesrep",format:"?"},

4 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay Rusev
Telerik team
answered on 07 Mar 2012, 10:32 AM
Hello Patrick,

Yes because the code applies only on the first numeric text box. See the javascript for more details. You can for-each the inputs and set the format.

columnFilterMenu.form.find("[" + kendo.attr("type") +"=number]").each(function() { $(this).data("kendoNumericTextBox").options.format="n0"; });

Greetings,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Patrick Rioux
Top achievements
Rank 1
commented on 07 Mar 2012, 03:56 PM

Thanks. It work like a charm!
0
Nikolay Rusev
Telerik team
answered on 27 Feb 2012, 09:08 AM
Hello Patrick,

The format is as follow: format: "{0:c}".

See the formatting of UnitPrice column in the following demo:
http://demos.kendoui.com/web/grid/editing.html

Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Patrick Rioux
Top achievements
Rank 1
commented on 27 Feb 2012, 03:44 PM

I think you misunderstood my issue.
Look on my screen example, this is for the filter column.

1. My salesrep column is a numeric with no decimal. When the focus is on the filter, everything is good. When I tab out, the field is shown with two decimals. (check print screen attached). Not sure what is the exact format I need to add to make this work.

2. Where I can find the documentation of the format: ?

Thanks.
Nikolay Rusev
Telerik team
commented on 29 Feb 2012, 10:36 AM

Hello Patrick,

Currently the input options for filter menu can only be configured only as shown bellow:
var grid = $("#grid").data("kendoGrid"),
      columnFilterMenu = grid.thead.find("th[data-field=OrderID]").data("kendoFilterMenu");
 
columnFilterMenu.form.find("[" + kendo.attr("type") + "=number]")​.data("kendoNumericTextBox").options.format="n0"​​​​​​​​​​​​​​​​​​​​;

By changing the format of the input the value shown blur will not be formatted as decimal number.
You can find more details on the article bellow:
http://www.kendoui.com/documentation/framework/globalization/overview.aspx

Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Patrick Rioux
Top achievements
Rank 1
commented on 29 Feb 2012, 03:25 PM

Did you test your code? I tried the following and still have the issue.
Don't know what I did wrong.

   var grid $("#grid").data("kendoGrid")
            var columnFilterMenu grid.thead.find("th[data-field=SalesrepId").data("kendoFilterMenu");
            columnFilterMenu.form.find("[" kendo.attr("type") "=number]").data("kendoNumericTextBox").options.format="n0";
          }

Nikolay Rusev
Telerik team
commented on 02 Mar 2012, 05:20 PM

Hello Patrick,

Inspect the OrderID column in the following jsFiddle:
http://jsfiddle.net/rusev/kfn43/1/

Greetings,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Patrick Rioux
Top achievements
Rank 1
commented on 04 Mar 2012, 03:01 AM

Almost working. Only the first control has the right format.
The is the same bug in jsFiddle sample. Don't know how to fix the second one.
ThinkSmart
Top achievements
Rank 1
commented on 04 Feb 2016, 02:21 PM

Hello, 

This is clearly a telerik bug and it is almost 4 years old now. Has it been fixed?

 Thanks

Nikolay Rusev
Telerik team
commented on 09 Feb 2016, 09:12 AM

Hello,

 

Column format is not automatically picked by the filter menu. It is related to the mechanism used for initialization of widgets, namely MVVM binding, where you cannot set the format of NumericTextBox as attribute.

In order to have more fine grained control over the widget initialization you can use filterable.ui function instead.

 

Regards,
Nikolay Rusev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Masaab
Top achievements
Rank 1
answered on 24 Mar 2014, 11:50 PM
This is a custom Format:
where you can use '.' or ',' as separator

columns:[
         {
            field: 'MyNumericalDigits',
            title: 'NDigits',
           format: '{0:0.00}'
         }
]
0
Aharon
Top achievements
Rank 1
answered on 06 Feb 2015, 10:00 PM
If you are looking for a number with commas like 217,499 or 2,133.40 (no currency symbol). Then use format: "{0: #,##}". Your JSON element should look like:
{ field: "Amount", title: "Unit Amount", format: "{0:#,##}" }
Tags
Grid
Asked by
Patrick Rioux
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Masaab
Top achievements
Rank 1
Aharon
Top achievements
Rank 1
Share this question
or