惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News and Events Feed by Topic
F
Fortinet All Blogs
J
Java Code Geeks
GbyAI
GbyAI
Engineering at Meta
Engineering at Meta
P
Privacy International News Feed
V
Visual Studio Blog
Martin Fowler
Martin Fowler
博客园 - 司徒正美
A
Arctic Wolf
M
MIT News - Artificial intelligence
Blog — PlanetScale
Blog — PlanetScale
U
Unit 42
Scott Helme
Scott Helme
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Proofpoint News Feed
P
Palo Alto Networks Blog
S
Securelist
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Threatpost
S
SegmentFault 最新的问题
AWS News Blog
AWS News Blog
MongoDB | Blog
MongoDB | Blog
Apple Machine Learning Research
Apple Machine Learning Research
K
Kaspersky official blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
The Exploit Database - CXSecurity.com
Google DeepMind News
Google DeepMind News
A
About on SuperTechFans
月光博客
月光博客
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
CXSECURITY Database RSS Feed - CXSecurity.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
NISL@THU
NISL@THU
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Latest news
Latest news
Y
Y Combinator Blog
PCI Perspectives
PCI Perspectives
S
Security Affairs
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog RSS Feed
O
OpenAI News
Google Online Security Blog
Google Online Security Blog
The Hacker News
The Hacker News
博客园 - Franky
Attack and Defense Labs
Attack and Defense Labs
Hugging Face - Blog
Hugging Face - Blog
N
Netflix TechBlog - Medium
The GitHub Blog
The GitHub Blog
T
Troy Hunt's Blog

博客园 - 咕咕传说

屠夫兄的思路龙头思维 走刀口交割单 批量杀死锁 咕咕 111 Nginx配置多个server RestSharp的简单用法 缓存类2 关于运行在Docker的程序,无法远程访问数据库的解决方案! 重要的开源项目 SQL 某月每天的数据 或者某天每小时的数据 或者 某段时间每个月月数据,和该月每天的数据 Asp.net获取客户端的IP地址排除::1 EF 筛选列包含NULL会报错 博文阅读密码验证 - 博客园 .NET CORE 发布IIS问题收集 VS2019最新源代码管理工具+附下载地址 关于Mysql可视化工具Navicat Premium12激活使用【亲测】 经典SQL 语句 博文阅读密码验证 - 博客园 事务的四种隔离级别 [转载]
layUI关于table编辑列支持方向键功能
咕咕传说 · 2020-04-20 · via 博客园 - 咕咕传说

最近使用layui的框架时,发现table插件不支持键盘快捷键切换单元格,花了点时间实现此功能。

分享给有需要的朋友们~~~

   /*
    *编辑数据表格,键盘快捷键方法。
    *可跳过无编辑属性的列
    *tab 右边一个单元格
    *shift + tab 左边一个单元格
    *enter 下一行的单元格
    *shift + enter 上一行的单元格
    */
    //支持tab+enter 的切换
    //$(document).on('keydown keyup', '.layui-input',
    //    function (event) {
    //        var td = $(this).parent('td'),
    //            index = td.index(),
    //            tr = td.parent('tr'),
    //            isShift = $(document).data('shift'),
    //            isKeydown = (event.type == "keydown");
    //        switch (event.key) {
    //            case "Shift":
    //                $(document).data('shift', isKeydown);
    //                break;
    //            case "Tab":
    //                event.preventDefault();
    //                isKeydown && td[isShift ? 'prevAll' : 'nextAll']('[data-edit="text"]:first').click();
    //                break;
    //            case "Enter":
    //                isKeydown && tr[isShift ? 'prev' : 'next']().children('td').eq(index).click();
    //                break;
    //        }
    //    }); 
    //方向键的切换
    $(document).on('keydown', '.layui-table-edit', function (e) {
        var td = $(this).parent('td'),
            tr = td.parent('tr'),
            trs = tr.parent().parent().find("tr")
        tr_index = tr.index(),
            td_index = td.index(),
            td_last_index = tr.find('[data-edid="text"]:last').index(),
            td_first_index = tr.find('[data-edid="text"]:first').index();

        switch (e.keyCode) {
            case 13:
            case 39:
                td.nextAll('[data-edit="text"]:first').click();
                if (td_index == td_last_index) {
                    tr.next().find('td').eq(td_first_index).click();
                    if (tr_index == trs.length - 1) {
                        trs.eq(0).find('td').eq(td_first_index).click()
                    }
                }
                setTimeout(function () {
                    $('.last-table-edit').select()
                }, 0)
                break;
            case 37:
                td.prevAll('[data-edit="text"]:first').click();
                setTimeout(function () {
                    $('.last-table-edit').select()
                }, 0)
                break;
            case 38:
                tr.prev().find('td').eq(td_index).click();
                setTimeout(function () {
                    $('.last-table-edit').select()
                }, 0)
                break;
            case 40:
                tr.next().find('td').eq(td_index).click();
                setTimeout(function () {
                    $('.last-table-edit').select()
                }, 0)
                break;
        }
    }); 

View Code