[GRID]
@(Html.EJ().Grid<SyncfusionMvcApplication9.OrdersView>("FlatGrid")
. . .
.Columns(col =>
{
. . . col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(75).Add();
. . .
})
.ClientSideEvents(eve=>eve.QueryCellInfo("QueryCellInfo"))
)
<script>
function QueryCellInfo(args) {
if (args.column.field == "Freight" && args.data.Freight == 29.46) {
args.cell.innerHTML = ej.format(args.data.Freight, "C2", "en-GB");//Changing the currency format dynamically
}
if(args.column.field == "Freight" && args.data.Freight == 61.02)
args.cell.innerHTML = ej.format(args.data.Freight, "C2", "en-AU");//Changing the currency format dynamically
}
</script>
[_Layout.html page]
<link rel='nofollow' href="@Url.Content("~/Content/ej/web/Default-theme/ej.widgets.all.min.css")" rel="stylesheet" />
<. . .>
<script src="@Url.Content("~/Scripts/ej/ej.web.all.min.js")"></script>
<script src="@Url.Content("~/Scripts/ej/ej.unobtrusive.min.js")"></script>
<script src="~/Scripts/ej/cultures/ej.culture.en-AU.js"></script>
<script src="~/Scripts/ej/cultures/ej.culture.en-GB.js"></script>
|
Thank you. It worked perfectly.
I created a mapping function to map my currencies to cultures (Ex. 'EUR' => 'de-DE'). I also found the culture definition files for the 15 currencies I needed and minified them into one JS file.
The ej.format function is great. I am now also using it outside of the grid for currency formatting on other pages.
Thanks.
Index.cshtml
<ejs-grid id="Grid" dataSource="ViewBag.DataSource">
. . . .
</ejs-grid>
<script>
document.addEventListener('DOMContentLoaded', function () {
setCulture();
});
function setCulture() {
ej.base.setCulture('pt'); // set the actual culture name here
ej.base.setCurrencyCode('BRL'); // Change the currency code ( default BRL’s sign: R$)
loadCultureFiles('pt');
}
function loadCultureFiles(name) {
var files = ['ca-gregorian.json', 'numbers.json', 'currencies.json', 'timeZoneNames.json'];
if (name === 'pt') {
files.push('numberingSystems.json');
}
var loader = ej.base.loadCldr;
var loadCulture = function (prop) {
var val, ajax;
if (name === 'de' && prop === files.length - 1) {
ajax = new ej.base.Ajax(location.origin + location.pathname + '/../../js/cldr-data/supplemental/' + files[prop], 'GET', false);
}
else {
ajax = new ej.base.Ajax(location.origin + location.pathname + '/../../js/cldr-data/main/' + name + '/' + files[prop], 'GET', false);
}
ajax.onSuccess = function (value) {
val = value;
loader(JSON.parse(val)); // get the cldr-data in JSON format
};
ajax.send();
};
for (var prop = 0; prop < files.length; prop++) {
loadCulture(prop);
}
}
</script> |