summaryrefslogtreecommitdiffstats
path: root/qx08/source/class/tr/ui/Cellrenderer.js
blob: 79edf4d4e1e6ee44b8408badb5ec4b2bb8e99471 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* ************************************************************************

   Tr Frontend

   Author:
     * Tobias Oetiker

************************************************************************ */

/* ************************************************************************
#module(Tr)
************************************************************************ */

/**
 * A configurable cell renderre
 */
qx.Class.define('tr.ui.Cellrenderer', {
    extend : qx.ui.table.cellrenderer.Number,


    /**
                                            * Format a number with a configurable number of fraction digits
                                            * and add optional pre and postfix.
                                            * @param digits {Integer} how many digits should there be. Default is 0.
                                            * @param prefix {String} optional prefix.
                                            * @param postfix {String} optional postfix.
                                            */
    construct : function(digits, postfix, prefix) {
        if (digits == undefined) {
            digits = 0;
        }

        this.base(arguments);
        var format = new qx.util.format.NumberFormat();

        format.set({
            maximumFractionDigits : digits,
            minimumFractionDigits : digits
        });

        if (postfix != undefined) {
            format.setPostfix(postfix);
        }

        if (prefix != undefined) {
            format.setPrefix(prefix);
        }

        this.setNumberFormat(format);
    }
});