We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Format a currency column

Thread ID:

Created:

Updated:

Platform:

Replies:

126139 Sep 26,2016 06:50 PM Sep 29,2016 11:28 PM ASP.NET MVC 5
loading
Tags: Grid
Dayne
Asked On September 26, 2016 06:50 PM

Hi

I want to set the format of currency, with negatives values, if the value of the column is -200, I want that the result is -$200, rigth now it shows that the value is ($200)

Karthick Kuppusamy [Syncfusion]
Replied On September 27, 2016 09:29 AM

Hi Dayne, 

Thanks for Contacting Syncfusion Support. 

We have analyzed your requirement and while we set the negative value for the currency column the jquery currency format will be automatically convert the negative value to the parenthesis value. 

This is the default behavior. 

Please find the link for your reference. 

Regards, 
K.Karthick. 


Dayne
Replied On September 27, 2016 10:22 AM

Hi, but I don't want the default behavior, I want the negative result, for example:

If the value is: 200 the result sould be $200.00

If the value is: -200 the result sould be -$200.00 instead of ($200)

Is this posible?

Karthick Kuppusamy [Syncfusion]
Replied On September 29, 2016 04:37 AM

Hi Dayne, 

We have analyzed your requirement and we can change the format for Currency values through the QueryCellInfo event of the grid. 

Please find the code example. 

@(Html.EJ().Grid<object>("FlatGrid") 
        .Datasource((IEnumerable<object>)ViewBag.datasource) 
        . 
        . 
        . 
        .EditSettings(edit=>{edit.AllowAdding().AllowDeleting().AllowEditing(); }) 
         .ClientSideEvents(e => e.QueryCellInfo("QueryCellInfo")) 
         .Columns(col => 
          { 
            col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add(); 
            col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add(); 
            col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(75).Add(); 
            col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(75).Format("{0:C}").Add(); 
            col.Field("ShipCity").HeaderText("Ship City").Width(110).Add(); 
             
        })) 
</div> 
 
<script>  
    function QueryCellInfo(args) { 
        if (args.column.field == "Freight" && args.data.Freight < 0) { 
            args.cell.innerHTML = "-" + ej.format(args.data.Freight * -1, "C2"); 
        } 
    } 
</script> 


For your reference we have created a sample based on your requirement and same it can be downloaded from the following location. 

Please refer the following UG Link for more information. 

Regards, 
K.Karthick. 


Dayne
Replied On September 29, 2016 09:42 AM

Thanks very much, this solucion works fine.

Karthick Kuppusamy [Syncfusion]
Replied On September 29, 2016 11:28 PM

Hi Dayne, 

Thanks for the update. 

We are happy to hear that your requirement is achieved. 

Regards, 
K.Karthick. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;