Forum

July 10th, 2011
You must be logged in to post Login Register

Search Forums:


 






populate array using addRowData with array

UserPost

04:54
11/01/2013


GeorgeG

UK

New Member

posts 2

Post edited 12:04 – 11/01/2013 by GeorgeG


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 :)

13:43
11/01/2013


OlegK

Germany

Member

posts 1210

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.

10:36
12/01/2013


tony

Sofia, Bulgaria

Moderator

posts 7375

Post edited 10:37 – 12/01/2013 by tony


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:20
12/01/2013


OlegK

Germany

Member

posts 1210

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


About the jQuery Grid Plugin – jqGrid forum

Most Users Ever Online:

215


Currently Online:

44 Guests

Forum Stats:

Groups: 1

Forums: 7

Topics: 10274

Posts: 30353

Membership:

There are 11038 Members

There have been 448 Guests

There is 1 Admin

There are 2 Moderators

Top Posters:

OlegK – 1210

markw65 – 179

kobruleht – 144

phicarre – 132

YamilBracho – 124

Renso – 118

Administrators: admin (60 Posts)

Moderators: tony (7375 Posts), Rumen[Trirand] (81 Posts)




Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information