Forum

May 22nd, 2014
A A A

Please consider registering
guest

Log In Register

Register | Lost password?
Advanced Search

— Forum Scope —

  

— Match —

   

— Forum Options —

    

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

Topic RSS Related Topics
populate array using addRowData with array
11/01/2013
04:54
GeorgeG
UK
New Member
Forum Posts: 2
Member Since:
11/01/2013
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
OlegK
Germany
Member
Forum Posts: 1233
Member Since:
10/08/2009
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
tony
Sofia, Bulgaria
Moderator
Forum Posts: 7679
Member Since:
30/10/2007
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 PHP, ASP.NET and ASP.NET MVC visit us at our commercial products site - trirand.net - by the very same guys that created jqGrid.
12/01/2013
12:20
OlegK
Germany
Member
Forum Posts: 1233
Member Since:
10/08/2009
Offline

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

Forum Timezone: Europe/Sofia

Most Users Ever Online: 215

Currently Online:
30 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1233

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11320

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10527

Posts: 31121

Newest Members: Shahid1, sheryl.liang@db.com, JuanPC, Loganathan.S, krish, jqGridForStruts

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

Administrators: admin: 61

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information