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
Multiselect with shift to emulate the same behaviour as in the file explorer
15/04/2009
07:06
Avatar
Markus
Member
Members
Forum Posts: 15
Member Since:
15/04/2009
sp_UserOfflineSmall Offline

Hi,

i want to extend the jqGrid so it has the same select behaviour as the file explorer. For example selecting row 3 + shift + selecting row 10 selects every row between them. Is that possible ?

Regards
Markus

16/04/2009
03:11
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello,

Currently no, but you can play little with this using onSelectRow event.

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.

16/04/2009
03:16
Avatar
Markus
Member
Members
Forum Posts: 15
Member Since:
15/04/2009
sp_UserOfflineSmall Offline

Hi Tony,

thx for the fast answer!

I tried this already, but the javascript mouse event is missing. So it's not possible to detect the currently pressed key 🙁

Regards
Markus

16/04/2009
03:56
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello,

Try with the option multikey - see docs.

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.

29/07/2009
13:42
Avatar
jbingham
New Member
Members
Forum Posts: 2
Member Since:
29/07/2009
sp_UserOfflineSmall Offline

I also want to get the behavior you describe, Markus.  Multikey didn't do quite what I wanted, but for the limited case I need, I got it to work by doing three things:

1. calling hideCol(”cb”) to remove the checkboxes

2. suppressing the browser's default handling of shift clicks with:

    $(table).mousedown(function(e) { if (e.shiftKey) return false; });

3. modifying grid.base.js to handle standard mouse behaviors like in file explorer and the grids from extjs and dojo

Replace line 1710 of grid.base.js in 3.5-beta with this:

 if (!e.ctrlKey && !e.shiftKey) // click clears selection

    $(ts).resetSelection();

if (e.shiftKey && ts.p.selrow && ts.p.selrow != ptr[0].id) { // grow selection on shift

    var i = $(ts.rows).index($(”#” + ts.p.selrow));

    var j = $(ts.rows).index($(”#” + ptr[0].id));

    if (i > j) { var tmp = i; i = j; j = tmp; }

    for (var k = i; k <= j; ++k) {

        ptr = $(ts.rows).slice(k, k + 1);

        if(!ptr.hasClass(”ui-state-highlight”)) // don't remove current selections

            $(ts).setSelection(false, true, ptr);

}

else {

    $(ts).setSelection(false, true, ptr);

}

I can send the whole file if anyone's interested.  I'm sure Tony would know how to make it much more efficient and how to integrate it better into the code so it's available for other options too.  But this got me what I needed and I hope it's helpful to others too.
Cheers,
Jonathan 

29/07/2009
16:38
Avatar
jbingham
New Member
Members
Forum Posts: 2
Member Since:
29/07/2009
sp_UserOfflineSmall Offline

Version 1.8 of jquery ui.selectable is scheduled to provide support for ctrl and shift click:

http://dev.jqueryui.com/ticket/4205

http://dev.jqueryui.com/ticket/2946

Will be nice to see it in jqGrid too!

Cheers,

Jonathan

21/09/2009
14:45
Avatar
turya
Member
Members
Forum Posts: 7
Member Since:
20/03/2009
sp_UserOfflineSmall Offline

Or, without having to modify grid.base:

 
add to options:

    gridComplete: function() {
        $(".cbox").shiftSelect();
    },

add elsewhere:

jQuery.fn.shiftSelect = function() {
    var checkboxes = this;
    var lastSelected;
    var executing = false;
    jQuery(this).click( function(event) {
        
        if (executing)
            return;
            
        if ( !lastSelected ) {
            lastSelected = this;
            return;
        }
    
        if ( event.shiftKey ) {
            var selIndex = checkboxes.index(this);
            var lastIndex = checkboxes.index(lastSelected);
            /*
             * if you find the "select/unselect" behavior unseemly,
             * remove this assignment and replace 'checkValue'
             * with 'true' below.
             */
            var checkValue = lastSelected.checked;
            if ( selIndex == lastIndex ) {
                return true;
            }
            executing = true;
            var end = Math.max(selIndex,lastIndex);
            var start = Math.min(selIndex,lastIndex);
            for(i=start;i<=end;i++) {
                if (checkboxes[i].checked != checkValue)
                    $(checkboxes[i]).click();
            }
            executing = false;
        }
        lastSelected = this;
    });
}

shiftSelect lifted from: http://clownsinmycoffee.net/20.....th-jquery/

21/09/2009
17:30
Avatar
markw65
Member
Members
Forum Posts: 179
Member Since:
30/07/2009
sp_UserOfflineSmall Offline

Here's another one (I posted a more complex variant a few weeks ago - tony has since added the event parameter to the beforeSelectRow handler, which makes it much cleaner now).

Just set this as the beforeSelectRow handler (it will take care of shift and ctrl clicks in the "expected" manner).

function multiSelectHandler(sid, e) {
        var grid = $(e.target).closest("table.ui-jqgrid-btable");
        var ts = grid[0], td = e.target;
        var scb = $(td).hasClass("cbox");
        if ((td.tagName == 'INPUT' && !scb) || td.tagName == 'A') {
            return true;
        }
        var sel = grid.getGridParam('selarrrow');
        var selected = $.inArray(sid, sel) >= 0;
        if (e.ctrlKey || (scb && (selected || !e.shiftKey))) {
            grid.setSelection(sid,true);
        } 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(row.id, false);
                    }
                }
            } else if (!selected) {
                grid.resetSelection();
            }
            if (!selected) {
                grid.setSelection(sid,true);
            } else {
                var osr = grid.getGridParam('onSelectRow');
                if ($.isFunction(osr)) {
                    osr(sid, true);
                }
            }
        }
    }

Mark

25/09/2009
03:54
Avatar
dlee
Member
Members
Forum Posts: 15
Member Since:
24/09/2009
sp_UserOfflineSmall Offline

I was wondering what the maintainer's position on this was. I would like this behavior as well in jqGrid. Hopefully, it could use jQuery's selectable module instead of using its own custom implementation.

25/09/2009
05:48
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Just delete my post, Sorry

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