Forum
12:06
30/09/2011
Hi everyone,
I've encountered an issue when using subgrids and virtual scrolling where some rows will not expand when clicked, while others work fine.
After doing some digging I discovered that the reason some of them are not opening is because the event which opens them is being fired twice (the first one opening it, the second one closing it straight away). It seems that the click event to expand the subgrid is being bound properly the first time, but because of how virtual scrolling is implemented when additional rows are added to the grid the click events for the subgrids is being bound again to all the rows in the grid (including the ones already in there), so the function to expand a subgrid is being bound twice.
I get the bug with the following config. The url and colModel are different when I actually test it (I can't post the real code here).
url: 'search.php',
colModel: [{name: 'col1', label: 'Column 1'}],
cmTemplate: {width: 100},
jsonReader: {repeatitems: false},
datatype: 'json',
height: 400,
mtype: 'POST',
rowNum: 20,
scroll: 1,
subGrid: true
subGridRowExpanded: function(subgridId, rowId) {
$('#'+subgridId).append($('<p>Some text</p> '));
}
});
With this config I scroll down a litle bit (until the grid loads the next page) and then try to expand one of the rows which was already in the grid, which now does nothing.
If there's something I'm doing wrong then I'd be happy to hear it. At the moment I'm still searching for a work around.
Edit: My first attempt at solving the issue was the edit the grid code to unbind the click event before it binds it a second time. I edited the code in 'addSubGrid' from:
to:
$(ts.rows[i].cells[pos]).bind('click.jqGrid', function(e) {
Basically I added the click event to the jqGrid namespace and removed all the click events in that namespace prior to adding them (thereby stopping the event from being bound twice).
As far as I can tell jquery event namespaces aren't used in the grid code, so this shouldn't conflict with existing code. In the future if all the events were namespaced this might cause issues if the grid binds other functions to the click event of the row, so it's not an ideal solution.
Alternatives to this include storing a reference to the function so it can be unbound latter or (perhaps the better solution) ensure that addsubgrid doesn't set up the subgrid twice on a single row in the first place. I haven't thought of a workaround which doesn't involve changing the grid code somehow.
Thanks,
Michael.
Most Users Ever Online: 715
Currently Online:
36 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.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66