Author Topic: Option to display and(!) enter numeric values with SI unit prefixes  (Read 3875 times)

Jens

  • Newbie
  • *
  • Posts: 5
    • View Profile
I wonder if it is possible to make Paramquery (Pro) display, and also allow entering, of SI unit prefixes and powers of 10 in certain cells?
See https://en.wikipedia.org/wiki/Unit_prefix
This way, I can enter "520k" and it will be displayed as "520k" but the underlying data will have 520000. Or 1.4G (=1400000000), "0.9u" (=0.0000009), etc.
If I enter "520000" it will be automatically reformatted as "520k" but saved as 520000 (pure numeric value).
And if I enter "0.9e-3" or "1.78e10" it will be parsed as "0.0009" and "178000000" respectively.

This would make entering numeric values much much easier, especially for scientific data.
The system should accept SI and exponential entry, but be configurable to display only in one format, so the display is always consistent.
(Note that SI prefixes are case sensitive, "m" and "M" are different; but the "e" for powers of 10 (Exponent) is not. "E" is also possible.

Currently, for cells that are defined to only accept numeric data, this is not possible; non-numeric characters are filtered.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Option to display and(!) enter numeric values with SI unit prefixes
« Reply #1 on: October 15, 2018, 11:09:55 am »
This is possible by using.

1) column.format function to format numbers to SI format.

2) column.deFormat to enable range filtering of such data.

3) Disable numeric filtering in fields by setting option: filterModel.filterKeys.

4) column.editor.getData to convert SI units to numbers. column.deFormat can be reused here.

Jens

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Option to display and(!) enter numeric values with SI unit prefixes
« Reply #2 on: October 16, 2018, 12:08:30 pm »
Thank you!
We will try it this way.

Do you have any code examples to put into a jsfiddle (etc) to get started?

Jens

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Option to display and(!) enter numeric values with SI unit prefixes
« Reply #3 on: March 13, 2019, 06:06:47 pm »
Hi!

Do you have a code example to put into a jsfiddle (etc) to get started with this topic?

Jens

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Option to display and(!) enter numeric values with SI unit prefixes
« Reply #4 on: March 19, 2019, 03:54:26 pm »
Hi Jens

Please check this https://next.plnkr.co/edit/NcCkqF4b3JHwXLqW

This is implementation of "k" only, similarly you could add other units.

Code: [Select]
{ title: "Revenues", width: 150,
                    //dataType: "float",
                    align:'right',
                    dataIndx: "revenues",
                    format: function(val){
                        //debugger;
                        if( (/\d+000$/).test(val+"") ){
                            return val/1000+"k"
                        }
                    },
                    editor: {
                        getData: function(ui){
                            debugger
                            var val = ui.$cell.find("input").val();
                            if( (/\d+k$/).test(val) ){
                                return val.substr(0, val.length-1)+"000";
                            }
                            return val;
                        }
                    }
                },
« Last Edit: March 19, 2019, 04:07:53 pm by paramquery »