I am looking to format the "amount" with maximum 13 decimal precision to populate a grid cell which i'm doing in the following way.
text box is
$(gridId + "#Units")
.parent()
.append("<input type='text' id='UnitsA' onkeyup
='checkdigit(this,\"Units\",8,13)' value='" + txval + "'></input>");
my .cshtml file has :
columns.Bound(p => p.Units)
.Width("20%")
.Title("Units")
.ClientTemplate("#: formatAmountTo13Dec(Units, '') #")
.HtmlAttributes(new { #class = "grid-number" })
;
the function formatAmountTo13Dec has the following.
function formatAmountTo13Dec(data, defaultValue)
{
return data != null ? kendo.format("{0:c13}", parseFloat(data)) : defaultValue;
}
When i enter -999.9999999999999 in the cell ( 999 followed by 13 decimals) it is formatted by calling the above function.
kendo.format("{0:c13}", parseFloat("-999.9999999999999"))
However this rounds up the amount and populates the cell with
(1,000.0000000000000), but the expected amount is (999.9999999999999)
To Avoid rounding up, instead of kendo.format, i tried kendo.toString() ,
But the result to this is -999.999999999999, without the brackets for negative number which is required for the amount field in the grid i have.
Can someone please help me out on how to achieve the expected with no rounding and with brackets for negative numbers.
Related
i am trying to sum all table column values and total of the values must be 1.
as shown in the image value the actual total of values is 1, but it is showing 1.0000000000000000000002.
i didn't getting where it is going wrong. i take the values from json file and values are same in json file as well. it must be error with decimal places. how to deal with this.
var sum = 0
var expectedSum=1
cy.get('td :nth-child(3) > input:visible').each(($el, index, $list) => {
// var result =parseFloat($el.val())
var result =$el.val()
sum=Number(sum)+Number(result)
cy.log(result)
}).then(function()
{
cy.log('allocation total:'+sum)
//assertion to check total alocation percent is 100
expect(sum).to.equal(expectedSum)
})
Check that the difference is below a certain threshold.
From the log it looks like your numbers are no more than 3 decimals, so
expect(Math.abs(1 - sum)).to.be.below(0.001)
i have a two columns in jqgrid, ShopID and NetSales, and i would like to add Contribution Column which will be a calculated column. the formula is NetSales divided by Total. please see image for example.
i know how to get the Total using getCol like this var sumtotal = grid.jqGrid('getCol', 'NetSales', false, 'sum');, but dont know how to use it further for division. i have tried, but it didnt work. please help.
i
Commonly you have two ways to solve the problem
As mentioned into the note you should calculate the sum of the column before to put the data into the grid. If you have this value you can use a custom fomatter to calculate the percentage. In this case the calculated sum should be defined as global in the scope.
Direct calculation of this without using any jqGrid method - see below
Suppose you have a local data like this
mydata = [
{ShipId: 1, NetSales: 150000},
{ShipId: 2, NetSales: 200000},
...
]
You can easy do (no checks it is just idea)
var sum = 0;
$.each(mydata, function( i, row) {
sum += parseFloat(row.NetSales);
}
$.each(mydata, function( i, row) {
if (sum > 0 ) {
row.Contribution = parseFloat(row.NetSales)/sum*100;
}
}
Then put mydata in jqGrid directly without to do any calculation and use custom formatter to display the percentage.
I'm unable to successfully reference a child grid's column data when creating a ClientTemplate for a column in the child's grid.
This works just fine and shows true/false correctly:
columns.Bound(m => m.Completed).Title("Completed").Width(100);
This does not work:
columns.Bound(m => m.Completed).Title("Completed").Width(100).ClientTemplate(
#"# if (Completed == true) { #" +
"<img src='" + Url.Content("~/Images/") + "checked.png' alt='quest icon' />" +
"# } else { #" +
"#: Completed #" +
"# } #"
);
The value, Completed, is always null therefore the else block is always hit and my Completed column just shows null for each row's value.
If I reference a parent grid column within else block I get the correct values so it seems as I'm missing something on how to reference the child columns.
Any direction would be appreciated.
Of course I found the answers about 20 minutes after I posted. You must escape the hash symbols in a nested grid. Credit here:
http://www.telerik.com/forums/conditional-client-template-in-razor-hierarchical-grid
I have date column in my grid, with format dd/MM/yyyy when I set field like 12/12/12 it updates grid with 11/12/12, (that happens due to silly time conversion:
kendo.parseDate('Mon Dec 12 2012 00:00:00 GMT+0100 (CET)').toISOString(). Is there any way to fix this?)
So I decided to stick with just 'Month Year'.
This is in grids columns array:
{ field: "published", title: "Published", format: "{0:MMMM yyyy}",
Dates are correct as Month Year on rows, but datepicker in edit mode pops up with 'day' precision, how do i tune it?
Ok I slapped it hard with the wrapper:
function Date2MDY(date) {
var dmy = '';
dmy += String(date.getMonth()+1) + '-'
dmy += String(date.getDate()) + '-'
dmy += String(date.getFullYear())
return dmy;
}
And it fixed the issue
I have a grid that implements grouping but would like to expand on the details that display in the groupText: area. Ideally I would be able to take data about that grouping and display in that group row with the group name ({0} default value).
In other words what I am trying to achieve is a way to display not only the group name but also some other data items contained in the JSON feed to the grid.
My searching seems to be coming up short on anyone being able to achieve this but I'm hoping someone can shed some light on expanding this setting and providing access to formating this area.
I find your question interesting, but the implementation is not simple. In the answer I showed before how one could use custom formatter in summary rows of the grouping.
In the demo you can see how to implement custom formatting of the grouping text. The demo display the following:
The implementation consist just from the implementation of the custom formatter which can be used for both purpose: formatting of the content of the corresponding column and formatting of the grouping text in case of grouping by the column. The code is a little tricky, but I hope that all will be able follow it. The code use the differences of the input parameters to define whether the formatter will be called to format the column content or to format the grouping text.
One part of the code which get the texts like "(test4,test7)" is not so effective in case of the usage of large number of rows, but it works.
Below is the code of formatter of the "Date" column which would by typically used with the predefined formatter: 'date'. I called in the part of the code the original Date-formatter, but used for the the grouping text more sophisticated code:
formatter: function (cellval, opts, rowObject, action) {
var fullOpts = $.extend({}, $.jgrid.formatter.date, opts),
formattedDate = $.fmatter.util.DateFormat('Y-m-d', cellval, 'd-M-Y', fullOpts),
groupIdPrefix = opts.gid + "ghead_",
groupIdPrefixLength = groupIdPrefix.length,
month = Number(cellval.split('-')[1]), // input format 'Y-m-d'
names = [], data, i, l, item;
// test wether opts.rowId start with opts.gid + "ghead_" and integer
// and rowObject is the array and action is undefined.
if (opts.rowId.substr(0, groupIdPrefixLength) === groupIdPrefix && typeof action === "undefined") {
// custom formating of the group header
// we just simulate some login by testing of the month > 9
// the next code fragment is not effective, but it can be used
// in case of not so large number of groups and the local data
data = $(this).jqGrid("getGridParam", "data");
for (i = 0, l = data.length; i < l; i++) {
item = data[i];
if (item.invdate === cellval) {
names.push(item.name);
}
}
return (month > 9 ? ('<span class="ui-icon ui-icon-alert" style="float: left;"></span>' +
'<span style="color:tomato; margin-left: 5px;">') : "<span>") +
formattedDate + ' (' + names.join() + ')</span>'
}
return formattedDate;
}
UPDATED: The fixed version of the demo is here. It uses $.fn.fmatter instead of currently removed from jqGrid method $.fmatter.util.DateFormat.