单击按钮获取数据表的行数据 [英] Get datatable's row data on button click

查看:83
本文介绍了单击按钮获取数据表的行数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对项目有问题.

我正在尝试创建一个Crud菜单,当单击编辑"按钮时,该行的数据将被传输到引导程序模式,并且用户可以从那里进行编辑.

I'm trying to create a crud menu, when hitting the Edit button the row's data will be transferred to a bootstrap modal and from there user will be able to edit.

问题:现在,当点击行时-模态会完美地打开行的数据-但是当我尝试通过按按钮('.edit_btn')来更改它以获取数据时,它不起作用.我知道该按钮不包含任何数据-所以这就是为什么它可能无法正常工作的原因....

Problem : right now when hitting the row - the modal opens perfectly with the row's data - but when i try to change it to get the data by pressing on the button ('.edit_btn') ,it dos't works. i know that the button doesn't holds any data - so that's why it's probably don't work....

 $('#example tbody').on('click',  '.edit_btn', function () { // works only 
    when replacing 'tr' with  '.edit_btn' //
    var data_row = table.row(this).data(); // row's data

    $("#myModal").modal('show');

    $('#myModal').on('shown.bs.modal', function() {

        $('#name').val(data_row.id);
        $('#type').val(data_row.type);
        $('#camp').html(data_row.campaign);

    });

});

谢谢

推荐答案

我将使用委托的事件处理程序tbody .edit_btn并通过closest('tr')抓行:

I would use a delegated event handler tbody .edit_btn and grab the row through closest('tr') :

$('#example').on('click', 'tbody .edit_btn', function () {
    var data_row = table.row($(this).closest('tr')).data();
    ...
})

叉状叉车-> https://plnkr.co/edit/58vkkp3M6d68uuMknXus?p =预览

forked plunkr -> https://plnkr.co/edit/58vkkp3M6d68uuMknXus?p=preview

这篇关于单击按钮获取数据表的行数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆