22
Views
10
Comments
Solved
Different Currency Symbols for different rows in datagrid

Hi,

In datagrid, based on another record values I've to set the currency symbols.

For eg,

If the first row and column one has an Id =25, then value on 1st row and 2nd column be dollars(85$) and for the next set if it has id =30, then it must be euros(780 € ). So it would be like as follows:

Id    Cost

1      85$

2      80 € and so on.

Thanks for any help in advance.

Solution
var GridFunctionsCurrency = {
    
  currencyRenderer: function(panel, row, column, cell) {
        if (panel.cellType == wijmo.grid.CellType.Cell) { // Only for cells, exclude grid header
            var value = panel.getCellData(row, column);            
            var r = panel.rows[row].dataItem;
            var currency = r.CurrencySymbol;
            if (String(value).split(".").length < 2 || String(value).split(".")[1].length<=2 ){
            value = Number(value).toFixed(2);
             }
              if (value !== null && value !== undefined && !isNaN(value)) {                  
                var _val = currency + value.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");                
                if (_val !== undefined && _val !== null && _val !== 'NaN') {
                return _val;
                }
            }
        }
    }
};

Using the cell renderer parameter, I've bound an attribute with currency symbol and concatenated the  symbol and the value. I've used the above script to achieve this
Rank: #90

Hi Balaji,

In this case you need to create one currency type static entity and store this Identifire in main entity when you save record.

Based on currency type you can add diffrent currency symbol in grid.


Hope thsi will help you.

Regards

Rahul

Hi,  

The FormatCurrency(,,,,) function formats your number and the second parameter is the currency symbol, it should be something like this : 

FormatCurrency(Value , if(Id=25,"$",If(Id=30,"€","?")),NumberOfDigits,DecimalSeparator,GroupSeparator))

Hope this helps

Graça 

 

Rank: #90

Hi Balaji,

you are setting condition from ID and id can be change from environment wise that not good practise.

Well @Maria alredy provide suggestion.


Regards

Rahul

Why not pass to the DataGrid the amount as text field with the value already formatted ? 

As they are from different currencies you are not going to do calculations with that column.


Solution
var GridFunctionsCurrency = {
    
  currencyRenderer: function(panel, row, column, cell) {
        if (panel.cellType == wijmo.grid.CellType.Cell) { // Only for cells, exclude grid header
            var value = panel.getCellData(row, column);            
            var r = panel.rows[row].dataItem;
            var currency = r.CurrencySymbol;
            if (String(value).split(".").length < 2 || String(value).split(".")[1].length<=2 ){
            value = Number(value).toFixed(2);
             }
              if (value !== null && value !== undefined && !isNaN(value)) {                  
                var _val = currency + value.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");                
                if (_val !== undefined && _val !== null && _val !== 'NaN') {
                return _val;
                }
            }
        }
    }
};

Using the cell renderer parameter, I've bound an attribute with currency symbol and concatenated the  symbol and the value. I've used the above script to achieve this