Forum
21:48
03/10/2013
Just found another problem with the averaging function. Same 30 rows, different column containing percentages. 7 of the 30 cells in this column are blank (see screenshot below where "v" is " " - presumably not truly blank so the browser styles the cell correctly). Because of the " " is not a number and fails parseFloat(), JQGrid calculates the average as "NaN".
22:43
03/10/2013
For anyone else that is having these problems, here's a revised "if" block with only a few minor changes.
NOTE: I did NOT thoroughly test this yet but it solved the problems I was encountering.
var ln = $t.rows.length, i = 0, den = 0;
if (ln && ln > 0)
{
while (i < ln)
{
if ($($t.rows[i]).hasClass('jqgrow'))
{
try
{
val = $.unformat.call($t, $($t.rows[i].cells[pos]), { rowId: $t.rows[i].id, colModel: $t.p.colModel[pos] }, pos);
} catch (e)
{
val = $.jgrid.htmlDecode($t.rows[i].cells[pos].innerHTML);
}
if (mathopr)
{
v = parseFloat(val);
if (!isNaN(v))
{
sum += v;
if (max === undefined) { max = min = v; }
min = Math.min(min, v);
max = Math.max(max, v);
den++;
}
}
else if (obj) { ret.push({ id: $t.rows[i].id, value: val }); }
else { ret.push(val); }
}
i++;
}
if (mathopr)
{
switch (mathopr.toLowerCase())
{
case 'sum': ret = sum; break;
case 'avg': ret = sum / den; break;
case 'count': ret = ln; break;
case 'min': ret = min; break;
case 'max': ret = max; break;
}
}
}
11:21
Moderators
30/10/2007
Hello,
Thank you very much. Yes, I confirm this is a bug in getCol method.
We do not consider in avg the first row which should be excluded.
About the case if the cell value is " " I think that in this case we should interpret it as 0.
What do you think about this?
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
15:51
03/10/2013
Hi Tony,
Actually, after I posted my solution, I realized I wrote a custom formatter for percentages that was inserting the single space. Can't remember why exactly as it seemed to perform the same way when I took the single space out. Maybe it was a typo on my part.
I would think that if the cell value is null or, when the white space is trimmed, equals empty string, then the cell's value should not count towards the average.
At the very least, I think that null and empty string should not count - I think you could make a case either way about the trimming of whitespace.
Thanks!
- Joe
11:07
Moderators
30/10/2007
Hello,
Thanks for the opinion.
Especially for the count I do not agree. Suppose we want to count string, then it is very natural to count all one.
I Have fixed this in git hub.
Regards
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
39 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66