0
votes

I have a Kendo Grid displaying dollar amounts but the data in the DataSource returns 4 decimal places.

The DataSource data looks something like this:

{ totalDollars: 1513.1548 },
{ totalDollars: 158.2903 },
{ ... }

So to display the number correctly I use the column format...

columns: [
    { field: 'totalDollars', format: '{0:c2}' },
    { ... }
]

But now I want to filter this column. If I filter with "Is Equal To" 159.29 it fails.

I've made it work using 4 decimals and using column.filterable.ui:

columns: [
    {
        field: 'totalDollars',
        format: '{0:c2}',
        filterable: {
            ui: function(e) {
                element.kendoNumericTextBox({
                    format: "n4",
                    decimals: 4
                });
            }
        }
    }
]

But this doesn't help because the user doesn't know the last 2 decimals. So I need it to only use up to 2 decimals when filtering.

Is this possible?

JSFiddle here - note that filtering by "Mono Cost" using 7133.03 doesn't work but 7133.0332 does. I'm looking to make 7133.03 work.

1

1 Answers

2
votes

I have updated the fiddle for you http://jsfiddle.net/53pqe3mo/2/

But essentially you can override the default parser for the value being returned by adding the following:

DefaultMonoCPP: {
                    editable: false,
                    type: "number",  
                    parse: function(e)
                    {
                        console.log(e);
                         return  kendo.parseFloat(kendo.toString(e,"c2"));  
                    }

I have added the console.log line just to show you that the value actually being passed in is the original supplied by the datasource.

It took a little finding but this link should help:

http://docs.telerik.com/kendo-ui/api/javascript/data/model#methods-Model.define

edit:

updated answer based on comments.

for future reference use this link:

http://docs.telerik.com/kendo-ui/framework/globalization/numberparsing