EasyUI Forum
September 15, 2025, 08:17:47 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: treegrid keyboard navigation  (Read 7190 times)
roberto
Jr. Member
**
Posts: 88


View Profile Email
« on: May 16, 2019, 09:18:43 PM »

Hi,

How to use the keyboard to navigate?
Logged
battlezad
Newbie
*
Posts: 44


View Profile
« Reply #1 on: May 16, 2019, 10:39:39 PM »

https://www.jeasyui.com/forum/index.php?topic=1381.0
Logged
aiit
Newbie
*
Posts: 12


View Profile Email
« Reply #2 on: June 02, 2019, 06:34:13 PM »

Code:
$.extend($.fn.treegrid.methods, {
    nav: function (jq) {
        return jq.each(function () {
            var t = $(this), o = t.treegrid('options'), a, l;
            var toArr = function (d) {
                $.each(d, function (i, x) {
                    a.push(x.id);
                    if (x.children) toArr(x.children);
                });
            }
            var skip = function (c, m) {
                var i = c + m;
                i = (i < 0) ? 0 : ((i > l) ? l : i);
                if (!isV(i))
                    skip(i, (i == l) ? -m : m);
                else
                    t.treegrid('select', a[i]);
            }
            var isV = function (x) {
                var c = t.treegrid("options").finder.getTr(t[0], a[x]);
                return $(c).is(':visible');
            }
            if (!o.hasSetEvents) {
                o.hasSetEvents = true;
                var u = o.onLoadSuccess;
                o.onLoadSuccess = function (row, data) {
                    a = [];
                    toArr(data);
                    l = a.length - 1;
                    u.call(this);
                };
            }
            t.treegrid('getPanel').panel('panel').attr('tabindex', 1).bind('keydown', function (e) {
                var k = e.keyCode;
                if (k == 38 || k == 40) {
                    var s = t.treegrid('getSelected');
                    var c = (s) ? $.inArray(s.id, a) : 0;
                    skip(c, (k == 38) ? -1 : 1);
                }
            });
        });
    }
});
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!