Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Bug in averaging function for footers?
03/10/2013
21:25
Avatar
joec2000
Member
Members
Forum Posts: 5
Member Since:
03/10/2013
sp_UserOfflineSmall Offline

See screenshot below. Data set sums to 24.12999, for 30 rows. Excel calculates average to be 0.80433. JQGrid calculates average to be 0.78 (rounded up from 0.778387). See snippet of JQGrid source code below where JQGrid is dividing 24.12999 by 31 instead of 30.

Image Enlarger

03/10/2013
21:48
Avatar
joec2000
Member
Members
Forum Posts: 5
Member Since:
03/10/2013
sp_UserOfflineSmall Offline

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".

Image Enlarger

03/10/2013
22:43
Avatar
joec2000
Member
Members
Forum Posts: 5
Member Since:
03/10/2013
sp_UserOfflineSmall Offline

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;
                            }
                        }
                    }

04/10/2013
11:21
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

04/10/2013
15:51
Avatar
joec2000
Member
Members
Forum Posts: 5
Member Since:
03/10/2013
sp_UserOfflineSmall Offline

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

06/10/2013
11:07
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

07/10/2013
15:54
Avatar
joec2000
Member
Members
Forum Posts: 5
Member Since:
03/10/2013
sp_UserOfflineSmall Offline

Yeah, that's why I was saying I think it could go either way.

As long as everything else works OK, the programmer can always "tweak" the values of the cells to get the grid to behave the way they want.

Thanks for fixing it so quickly!

- Joe

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
55 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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information