I'm attempting to convert the country code to the symbol for this I have used the below package. Currency formatting and conversion package for Laravel akaunting / laravel-money - (https://github.com/akaunting/laravel-money/blob/master/README.md)
I have a datable Child rows (show extra / detailed information)
when the user clicks on expand record it will show extra details parent record
before trying to use this package I have used tried something like:
var currency_symbols = {
'USD': '$', // US Dollar
};
...
$('#child_table').append("<tr><td>" + >>> currency_symbols[json[i].currency] <<< +" " + json[i].price + "</td><td></tr>");
Now I have a situation where I need to use this package helper function instead of currency_symbols[json[i].currency], but get any idea how to use this
$('#example tbody').on('click', 'td.details-control', function () {
var tr = $(this).parents('tr');
var row = datatable1.row(tr);
if (row.child.isShown()) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
}
else {
// Open this row (the format() function would return the data to be shown)
if (row.child() && row.child().length) {
row.child.show();
}
else {
row.child(childFunction(row.data())).show();
}
tr.addClass('shown');
}
});
function childFunction(rowData) {
div = $('<div/>');
$.ajax({
url: '...',
data: {
...
},
dataType: 'json',
success: function (json) {
div.html(json)
div.append("<table id='child_table'></table>");
if (json.length > 0) {
$('#child_table').append("<tr><th>Unit Price</th></tr>")
var len = json.length;
for (var i = 0; i < len; i++) {
$('#child_table').append("<tr><td>"+ ***currency_symbols[json[i].currency]*** +" "+json[i].proice+"</td><td></tr>");
}
}
}
});
return div;
}
Please help me with this how to manage it with HTML which resides in the js part on the AJAX call Any help would be great!
Also, suggestions are always welcome, if any of you are familiar with different packages also please share them with an example.
Thank you!