简体   繁体   English

jQuery Datatables-如何在单击该行中的按钮时获取该行的索引

[英]jQuery Datatables - How to get the index of a row when a button in that row is clicked

Here's what I'm attempting to do: 这是我正在尝试做的事情:

I have an edit button within every row. 每行中都有一个编辑按钮。 when the user clicks on that edit button, I need to get the index of that row..but I'm not sure how exactly to do that. 当用户单击该编辑按钮时,我需要获取该行的索引。.但是我不确定该怎么做。 Anyone know how to do this? 有人知道怎么做吗? Please check out my Datatables live link below to further understand my problem and make any necessary changes. 请查看下面的“我的数据表”实时链接,以进一步了解我的问题并进行必要的更改。

Datatables live link: http://live.datatables.net/madadak/2/edit 数据表实时链接: http : //live.datatables.net/madadak/2/edit

Thanks! 谢谢!

Change the jQuery code to be this: 将jQuery代码更改为:

$(document).ready( function () {
var table = $('#example').DataTable();
    $("#example tbody").on('click', '.editButton', function() {
        alert('Row index:' + $(this).closest('tr').prevAll().length );
    });                      
} );

It starts with index 0 which I hope is what you want. 它从索引0开始,我希望这是您想要的。 I found it here if you're wondering. 我想在这里找到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM