Giter VIP home page Giter VIP logo

revogrid-column-numeral's Introduction

๐Ÿšจ Repository Notice ๐Ÿšจ

This repo is read-only and will be deprecated in v5+ in favor of monorepos. Post issues here. Happy coding! ๐Ÿ–ฅ๏ธ๐Ÿ’ป


Number Column Type

Number column type for RevoGrid system based on numeraljs library.

Use any format you love to assign number format for your grid.

Installation

npm i @revolist/revogrid-column-numeral

Output

Number

Number Format String
10000 '0,0.0000' 10,000.0000
10000.23 '0,0' 10,000
10000.23 '+0,0' +10,000
-10000 '0,0.0' -10,000.0
10000.1234 '0.000' 10000.123
100.1234 '00000' 00100
1000.1234 '000000,0' 001,000
10 '000.00' 010.00
10000.1234 '0[.]00000' 10000.12340
-10000 '(0,0.0000)' (10,000.0000)
-0.23 '.00' -.23
-0.23 '(.00)' (.23)
0.23 '0.00000' 0.23000
0.23 '0.0[0000]' 0.23
1230974 '0.0a' 1.2m
1460 '0 a' 1 k
-104000 '0a' -104k
1 '0o' 1st
100 '0o' 100th

Currency

Number Format String
1000.234 '$0,0.00' $1,000.23
1000.2 '0,0[.]00 $' 1,000.20 $
1001 '$ 0,0[.]00' $ 1,001
-1000.234 '($0,0)' ($1,000)
-1000.234 '$0.00' -$1000.23
1230974 '($ 0.00 a)' $ 1.23 m

Usage in revo-grid:

import NumberColumnType from '@revolist/revogrid-column-numeral';
const columnTypes = {
    'numeric': new NumberColumnType('0,0')
};
const columns = [
    {
        prop: 'Num',
        name: 'My number',
        columnType: 'numeric'
    },
    {
        prop: 'Num2',
        name: 'My number2',
        columnType: 'numeric'
    }
];
const rows = [{
    'Num': 1000,
    'Num2': 1000
}];

const grid = document.querySelector('revo-grid');
grid.columnTypes = columnTypes;
grid.source = rows;
grid.columns = columns;


// '1,000'

Advanced

If you need to get numeric library instance you can do this as simple as:

import NumberColumnType from '@revolist/revogrid-column-numeral';
const numeral = NumberColumnType.getNumeralInstance;

numeral.register('format', 'percentage', {});

Also plugin provides access to beforeValueFormatted instance: emiter?: (event: string, instance: Numeral)

import NumberColumnType from '@revolist/revogrid-column-numeral';
const columnTypes = {
    'numeric': new NumberColumnType('0,0', (eventName, numeralInstance) => {
        // numeralInstance operations
    }),
};

revogrid-column-numeral's People

Contributors

dependabot[bot] avatar m2a2x avatar revolist avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

revogrid-column-numeral's Issues

Sorting a numeric column doesn't work as expected.

Sorting a column containing numeric values orders them as strings instead of numbers, even though the underlaying values in JS are numbers. For example, 9948 comes after 996 in descending order.

image

I'd expect to get the values from the screenshot in the following order: 9948, 9908, 996, 991, 99, 99

Is there any way to fix this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.