how to format a currency value differently in the same column of a grid?

I need to display in the same column of the grid a value of type currency, but making sure that the visible decimals are influenced by the value represented.
For example:
value greater than 1: two decimal places (9.01)
value less than 1: six decimal places (0.645321)
Is there a way?
Thanks for the support
Regards
Barbara Inzitari

3 Replies

MF Mohammed Farook J Syncfusion Team June 7, 2018 12:49 PM UTC

Hi Inzitari, 

Thanks for contacting Syncfusion support. 

We can’t apply different format in the same column at directly. This default behavior. But we can be achieved your requirement as a workaround by using ‘QueryCellInfo’ event of Grid. Please find the code example 
 

    @Html.EJS().Grid("FlatGrid").DataSource((IEnumerable<object>)ViewBag.dataSource).Columns(col => 
{ 
 
    col.Field("OrderID").HeaderText("Order ID").Width("120").IsPrimaryKey(true).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); 
    col.Field("CustomerID").HeaderText("Customer Name").Width("150").Add(); 
    col.Field("Freight").HeaderText("Freight").Width("120"). TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); 
}).AllowPaging().QueryCellInfo("QueryCellInfo").Render() 
</div> 
 
<script> 
    function QueryCellInfo(args) { 
        if (args.column.field == 'Freight') { 
            var value = parseFloat(args.cell.innerText); 
            args.cell.innerText = '$' + (value < 1 ? value.toFixed(6) : value.toFixed(2)) // change decimal ; 
        } 
    } 
</script> 


Please find the documentation and screenshot for your reference. 


 


Regards, 
J Mohammed Farook 



NI nimue June 8, 2018 03:20 PM UTC

Hi Mohammed,
thank you very much for your answer was just what I needed!!
Best Regards
Barbara Inzitari




MF Mohammed Farook J Syncfusion Team June 11, 2018 06:47 AM UTC

Hi Inzitari,  
 
Thanks for your feedback. 

We have happy to hear that your requirement is achieved. 

Thanks, 
J Mohammed Farook 


Loader.
Up arrow icon