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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 咕咕传说

屠夫兄的思路龙头思维 走刀口交割单 批量杀死锁 咕咕 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