EasyUI Forum
November 05, 2025, 09:39:35 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: Tree Grid Key Navigation  (Read 11605 times)
arma
Full Member
***
Posts: 110


View Profile
« on: February 09, 2015, 08:55:16 PM »

I refer to this http://www.jeasyui.com/forum/index.php?topic=483.0 to apply key navigation to grid. It works for datagrid but when i use it for treegrid it does not work and row becomes unselected. When i click using mouse it shows error : Uncaught TypeError: Cannot read property 'my_tree_id' of null

Any clue ?

 
Logged
bduguay
Newbie
*
Posts: 31


View Profile
« Reply #1 on: February 10, 2015, 09:08:03 AM »

This is what I have. currentGrid is set elsewhere since I have numerous grids on the page and only wanted to have the code once.

Code:
    $(currentGrid).treegrid('getPanel').attr('tabindex','-1').bind('keydown', function(e) {
    // Only allow the key up/key down events when the user is not editing the row.
        if (editingId == undefined) {
    // Prevent the default key press action
    e.preventDefault();
    // Up key - move to the previous row
    if (e.keyCode === 38) {
    var $curGrid = $(currentGrid),
    row = $curGrid.treegrid('getSelected'),
    gridData = $curGrid.treegrid('getData'),
    i = 0,
    found = false,
    previousRowId = 0;
    while ((i < gridData.length) && !found) {
    var gridRow = gridData[i];
    if (i === 0) {
    previousRowId = gridRow.id;
    }
    if (gridRow.children) {
    var j = 0;
    while (j < gridRow.children.length && !found) {
    child = gridRow.children[j];
    if (child.id === row.id) {
    found = true;
    } else {
    previousRowId = child.id;
    }
    j++;
    }
    } else if (gridRow.id === row.id) {
    found = true;
    } else {
    previousRowId = gridRow.id;
    }
    i++;
    }
    if (found) {
    $curGrid.treegrid('select', previousRowId);
    }
    // Down key - move to the next row
    } else if (e.keyCode === 40) {
    var $curGrid = $(currentGrid),
    row = $curGrid.treegrid('getSelected'),
    gridData = $curGrid.treegrid('getData'),
    i = gridData.length - 1,
    found = false,
    previousRowId = 0;
    while ((i >= 0 ) && !found) {
    var gridRow = gridData[i];
    if (i === gridData.length - 1) {
    previousRowId = gridRow.id;
    }
    if (gridRow.children) {
    var j = gridRow.children.length - 1;
    while (j >= 0 && !found) {
    child = gridRow.children[j];
    if (child.id === row.id) {
    found = true;
    } else {
    previousRowId = child.id;
    }
    j--;
    }
    } else if (gridRow.id === row.id) {
    found = true;
    } else {
    previousRowId = gridRow.id;
    }
    i--;
    }
    if (found) {
    $curGrid.treegrid('select', previousRowId);
    }
                         // space key - edit the row
    } else if (e.keyCode === 32) {
    editRow(batchDateDeptNum, false);
    }
        }
    });
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!