Dynamic number format in grids?

3 posts, 0 answers
  1. Marcus
    Marcus avatar
    17 posts
    Member since:
    Jul 2012

    Posted 12 Sep 2012 Link to this post

    Is it possible to format numbers based on variable rather than fixed values? I know that there are various ways you can
    do this normally, like padding etc but is it possible to do something directly in the grid?

    This is very important btw.
  2. OnaBai
    OnaBai avatar
    55 posts
    Member since:
    Aug 2012

    Posted 12 Sep 2012 Link to this post

    If you mean assign a format contained in a variable in creation time, you should do:
    var format = "n2";
    // For kendoNumericTextBox
    var number = $("#number").kendoNumericTextBox({
        format:format,
        value:12.34
    }).data("kendoNumericTextBox");
    // and for kendoGrid
    var gridFormat = "{0:n2}"
    var grid = $("#number").kendoGrid({
        dataSource:dataSource,
        columns:[
            ....
            {title:"Number", field:"number", format:gridFormat },
            ....
        ],
        editable:true
    });
    If you mean change the format as response to an event (for example, a click) then you should invoke the following code:
    // for numeric text box
    number.options.format =
    "n3";
    // for grid
    grid.columns[colNumber].format = "{0:n3}"
    For changing the format and then forcing a refresh of the field (writing its own value)
    // for numeric text box
    number.value(number.value());
    // for grid
    grid.refresh();
    Hope this works!!!
  3. Kendo UI is VS 2017 Ready
  4. Marcus
    Marcus avatar
    17 posts
    Member since:
    Jul 2012

    Posted 12 Sep 2012 Link to this post

    This looks like it could work. I will try and get back to you. Thank you in advance.

    Sorry, I was not clear enough. What I mean is that I have a second lookup field that contains the number of decimals for that field. It is a type of BI-solution where there is alot of different type of data depending on what KeyFigure you have.

    So in short. Is it possible to have the format defined by a dynamic variable. Maybe by using string padding or some type of function.
Back to Top