tonytomov / jqGrid

jQuery grid plugin
www.trirand.com
2.85k stars 1.2k forks source link

Custom formatter/unformat doesn't support arrays #877

Open meterlongcat opened 7 years ago

meterlongcat commented 7 years ago

Hi,

I've just written a custom formatter and unformat for a property containing a JavaScript array. Unfortunately this breaks with the jqGrid when the array is non-empty, more specifically when the array is of length 1.

The cause is this line of code: if(tmp === " " || tmp === " " || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}

As you can see the tmp.length===1 test will evaluate to true, causing charCodeAt to be called on an array which does not exist.

Should be able to fix this by changing to: if(!$.isArray(tmp) && (tmp === " " || tmp === " " || (tmp.length===1 && tmp.charCodeAt(0)===160)) ) {tmp='';}

Kind Regards, Jan

meterlongcat commented 7 years ago

Instead of !$.isArray(tmp) could instead test if tmp is a string. That's probably a better solution rather than trying to exclude all of the types that happen to have a length property.

tonytomov commented 7 years ago

Thanks, checking for string is better. Just curious - can you please provide a simple demo when this happen?

Thank you.

Kind Regards, Tony

meterlongcat commented 7 years ago

I just tried putting together a jsfiddle, however the only version of jqGrid available via CDN is 4.6. Do you know how I can reference 5.2.1?

tonytomov commented 7 years ago

Sorry for this. I hope CDN will be available in couple of days. For now use rawgit here is the link: https://cdn.rawgit.com/tonytomov/jqGrid/v5.2.1/js/jquery.jqGrid.js

Thank you

Kind REgards