Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





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

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
More control over click/select behavior
25/08/2009
11:48
Avatar
markw65
Member
Members
Forum Posts: 179
Member Since:
30/07/2009
sp_UserOfflineSmall Offline

i) beforeSelectRow doesnt have enough information passed to it. eg, I have an inline-editable multi-select grid:

  • If the user clicks on an editable field of a selected row, I want to start editing (not deselect the row, as would happen with a multiselect grid)
  • If the user clicks on a field thats already being edited, I dont want the normal select operations to happen at all (the <input> element will handle the click for me).
  • If the user clicks on the checkbox of a row thats being edited, I want to deselect the row, and finish the edit.

To acheive this, getting the event would help, as would getting the column.

ii) multiselect grids cant customize select behavior enough. I need to be able to customize:

  • click on row
  • click on checkbox
  • shift click on row
  • shift click on checkbox
  • ctrl click on row
  • ctrl click on checkbox

All in the same grid!

25/08/2009
15:43
Avatar
markw65
Member
Members
Forum Posts: 179
Member Since:
30/07/2009
sp_UserOfflineSmall Offline

So following up to my own post... after studying the grid code I found a way to do it - although its something of a hack, and rather fragile.

If beforeSelectRow could be passed the event object, and the column ix, I think I could do everything I want without any trickery.

For anyone else interested in a grid that supports shift-click to select ranges, ctrl-click to toggle rows, and handles clicks on editable fields smartly, the code follows. To use it set "multiselect:true,beforeSelectRow:function(){return false;}" in the grid options, and then add the handler as follows:

$(mygrid).bind("click",$(mygrid),multiSelectHandler);

where multiselectHandler is:

function multiSelectHandler(e) {
var grid = e.data;
var ts = grid[0], td = e.target;
var scb = $(td).hasClass("cbox");
var ptr = $(td).parents("tr.jqgrow");
if (!ptr.length || td.tagName == 'INPUT' || td.tagName == 'A') {
return true;
}
var sel = grid.getGridParam('selarrrow');
var sid = ptr[0].id;
var selected = $.inArray(sid, sel) >= 0;
if (e.ctrlKey || (scb && (selected || !e.shiftKey))) {
grid.setSelection(false,true,ptr);
} else {
if (e.shiftKey) {
var six = grid.getInd( sid);
var min = six, max = six;
$.each(sel, function() {
var ix = grid.getInd( this);
if (ix < min) min = ix;
if (ix > max) max = ix;
});
while (min <= max) {
var row = ts.rows[min++];
var rid = row.id;
if (rid != sid && $.inArray(rid, sel)<0) {
grid.setSelection( false, false, $(row));
}
}
} else if (!selected) {
grid.resetSelection();
}
if (!selected) {
grid.setSelection( false, true, ptr);
} else {
var osr = grid.getGridParam('onSelectRow');
if ($.isFunction(osr)) {
osr(sid, true);
}
}
}
}

26/08/2009
00:07
Avatar
markw65
Member
Members
Forum Posts: 179
Member Since:
30/07/2009
sp_UserOfflineSmall Offline

In case anyone tries to use it, the return condition should be:

if (!ptr.length || (td.tagName == 'INPUT' && !scb) || td.tagName == 'A') {
return true;
}

Mark

31/08/2009
11:21
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello Mark,

Thanks. As usual good catch - also added the event object to  beforeSelectRow event.

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
49 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.com

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

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information