Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KendoUI Grid Decimal number column

I have a column for weight (in Kg). When the user clicks on it I need to enable them to be able to put in decimal number with 3 places.

The problem I have is at the moment it only allows them to put it in to 2 places, but shows as 3 places. You can type in a number to many decimal places but when it saves it will round it to 2 places.

My column is set up like so:

...
{
        field: "weight",
        title: "Weight",
        width: 40,
        format: "n4",
        decimals: 4,
        step: 0.001,
        template: "#= weight.toFixed(3)+'kg' #"
}
...

I have tried a few things but none work.

like image 658
imperium2335 Avatar asked Mar 23 '13 20:03

imperium2335


1 Answers

Several questions (afaik):

  1. Format in columns is not defined as n4 but as {0:n4}.
  2. Formats are not just for the format of the number but might also include some text. Ex: {0:n4} Kg.
  3. For numeric columns, is not possible to specify attributes as decimals, step so you should define an editor function.

In addition, I don't understand your problems with decimals and round.

What I suggest is define the columns as:

{
    field: "weight",
    title: "Weight",
    width: 40,
    editor: numberEditor,
    format: '{0:n3} Kg.'
}

(assuming that you want three decimal precision) and define numberEditor as:

function numberEditor(container, options) {
    $('<input name="' + options.field + '"/>')
            .appendTo(container)
            .kendoNumericTextBox({
                format  : "{0:n3}",
                decimals: 3,
                step    : 0.001
            });
}
like image 76
OnaBai Avatar answered Oct 03 '22 09:10

OnaBai