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_Related Related Topics sp_TopicIcon
populate array using addRowData with array
11/01/2013
04:54
Avatar
GeorgeG
UK
New Member
Members
Forum Posts: 2
Member Since:
11/01/2013
sp_UserOfflineSmall Offline

Hello All,

I think I have found a bug in addRowData (grid.base.js), when using jqGrid with a local array.

If the rowid is not supplied, or does not exist in the source array, there is an attempt to fallback to the internal id generation mechanism, as follows (lines 2961-2962):

try {rowid = data[cnm];}
catch (e) {rowid = $.jgrid.randId();}

when data[cnm] does not exist Javascript (at least with the latest version of Chrome, Firefox IExplorer and a Web Browser (debian) 2.30.6) will not throw an exception for the assignment, so there is nothing to "catch".

The effect on the browser, is that the id of all the rows will be undefined.  As such when the user clicks any row, the first row is selected (as the string "undefined" is assigned to all the rowids).  The ids get populated properly if the rows are sorted (via a sortable column).

My temporary fix was to replace the two lines above with the following:

try { rowid = data[cnm];
    if(rowid ===undefined) {
        rowid = $.jgrid.randId();
    }
} catch (e) {rowid = $.jgrid.randId();}

I don't think that the "fix" above breaks anything.

p.s.: Don't ask me why I used jqGrid with an array and an undefined id column…

Regards,

GeorgeG

Edited to correct late night/early morning typing errors 🙂

11/01/2013
13:43
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

I think that the line

try {rowid = data[cnm];}

can be fixed to

try {rowid = data[cnm] || $.jgrid.randId();}

which is equivalent to (short form)

try {rowid = data[cnm] ? data[cnm] : $.jgrid.randId();}

Best regards
Oleg

P.S. I suppose that Tony will make the corresponding changes in the code of jqGrid after reading of your bug report.

12/01/2013
10:36
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello,

Thank you for the bug fix.

Oleg I do not think that your fix is fine.

Suppose the rowid becomes 0 (data[cnm]=0), then the logic will go to randid which is not correct.

I think that the fix from GeorgeG is ok and I will implent this fix.

Thanks again

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.

12/01/2013
12:20
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

You are right Tony! One should test only for undefined value.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
54 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