As for the retrieving data part, the behaviour of hitting the server several times before the mouse is released from the scroll bar seems to be consistent across all the browsers I tested, IE6, IE7, firefox, Safari and Chrome.
So the problem here is that you dont know when the user releases the mouse (or at least, I dont – perhaps there's a way!).
What happens, is that you get a series of "grid scrolled" events. To try to prevent hitting the server too many times, Ive set it up so that when a grid scrolled event occurs it kicks off a timer. If no new scroll event occurs within the next 200ms, it fetches the data, if a new one does occur, it resets the timer.
Perhaps 200ms is too short – but much longer than that and it will seem unresponsive.
1. The article that you post say that JSON is secure and eval is not safe.
It is not really true. I think that there is not complete secured thing. This is true for JSON too. I recommend you to read this http://directwebremoting.org/b…..it_is.html
in order to understand what is happen. Another good link is here
2. Appling JSON parse direct to jqGrid will cause the most user not use jqGrid. The reason is how the user configure your response from the server. Let make a example:
var a = '{"a":1}';
var b = "{'b':1}";
JSON.parse(a); //–> Result OK
JSON.parse(b); //–> Fail
eval('('+a+')'); //– Result OK
eval('('+b+')'); //– Result OK
I think you see the difference. When we use standart json encoder like in PHP json_encode and (there is such one in ASP) all is ok, but in case that this is not possible the most developers write thier response like in variable b. If you read the most messages in this forum connected to json response, you will see that about 50% of the responses that users post here is like the variable b.
But when goes to speed improvements I'm open and redy to apply them if they will not brake the existing code.
For my pleasure I have made some tests only in FireFox 3.5 comparing the times of parsing and I'm surprised how JSON.parse if fast.
The tests vary, but parsing 4 columns with 300 records – take 1ms with JSON.parse and 10ms with eval – wow 10 time faster.
In order that all will be happy I introduce another option in $.jgrid object called useJSON (default false) and have made the needed changes to the parse function (also published in the GitHub)