How to lose focus on a cell in SlickGrid

2019-07-27 06:54发布

问题:

My question is exactly opposite of this question. So what I'm trying is I'm trying to find a way to lose focus on a cell after user selects an item from the autocomplete combobox in that cell.

 $input.autocomplete({
                delay: 0,
                minLength: 0, 
                source: args.column.options,
                select: function (event, ui) {
                    $input.val(ui.item.label);
                   grid.getEditController().commitCurrentEdit();
              return false;
                }
            });

I used this code to lose focus indirectly after finishing with editing. It works fine, however, the cell stays selected somehow.

grid.getEditController().commitCurrentEdit();

I also tried the code below to lose focus but it throws error everytime when I run the code.

grid.setActiveCell();
grid.setSelectedRows(-1);

After selecting an item from the autocomplete combobox, I want the grid to lose focus and select nothing on the viewport of the grid.

Thanks for your answers in advance.

回答1:

Try calling grid.resetActiveCell().



回答2:

There was a commit made to the master branch last week that might address your issue: Fix keyboard focus getting trapped when cell has tabbable elements.



回答3:

You can achieve it as follows,


            if (grid.getActiveCell()) {
            var row = grid.getActiveCell().row;
            var cell = grid.getActiveCell().cell;
            grid.gotoCell(row, cell, false);
        }