Using tabbing in jeditable fields in datatables

烈酒焚心 提交于 2019-12-25 02:26:06

问题


Right now I have a datatable, some fields are editable, some are not. I have the following code (taken from tabbing between jeditable fields in a table):

$('#table .select').bind('keydown', function(evt) {
            if(evt.keyCode==9) {
                console.log("next");
                var nextBox='';
                var currentBoxIndex=$("#table .select").index(this);
                console.log("currentBoxIndex",currentBoxIndex);
                 if (currentBoxIndex == ($("#table .select").length-1)) {
                       nextBox=$("#table .select:first");         //last box, go to first
                       console.log("nextBox", nextBox);
                   } else {
                        nextBox=$("#table .select").eq(currentBoxIndex+1);    //Next box in line
                        console.log("nextBox", nextBox);
                   }
                $(this).find("#table  .select").blur();
                $(nextBox).click();  //Go to assigned next box
                return false;           //Suppress normal tab
            };
            }); 

This works great for tabbing to each editable field! Except one issue: I need to be able to tab to the field, select a value from a dropdown in the editable field, and then be able to tab. Right now I can tab through each one if I don't change the value in the field. If I change the value, the tabbing will stop and I have to re-click on the next field. Help?

I'm using:

datatables - http://datatables.net/

Bootstrap

jquery jeditable


回答1:


I found the solution.

        $('#table.select').bind('keydown', function(evt) {
                if(evt.keyCode === 9) {
                    console.log("next");
                    var nextBox = '';
                    var currentBoxIndex = $("#table.select").index(this);
                    console.log("currentBoxIndex",currentBoxIndex);
                    var showDropdown = function (element) {
                        var event;
                        event = document.createEvent('MouseEvents');
                        event.initMouseEvent('mousedown', true, true, window);
                        element.dispatchEvent(event);
                    };
                     if (currentBoxIndex === ($("#table.select").length-1)) {
                           nextBox = $("#table.select:first");         //last box, go to first   
                        showDropdown($(nextBox).get( 0 ));   
                       } else {
                            nextBox = $("#table.select").eq(currentBoxIndex+1);    //Next box in line                         
                            console.log("nextBox", nextBox);    
                            showDropdown($(nextBox).get( 0 ));   
                       }
                    $(this).find("#table.select").blur();                                                     
                    $(nextBox).click();  //Go to assigned next box                                      
                    return false;           //Suppress normal tab
                }
            }); 


来源:https://stackoverflow.com/questions/24935069/using-tabbing-in-jeditable-fields-in-datatables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!