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

…衆ロ難τιáo~ 提交于 2021-01-07 06:47:33

问题


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

Thanks!


回答1:


Change the jQuery code to be this:

$(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. I found it here if you're wondering.



来源:https://stackoverflow.com/questions/24498433/jquery-datatables-how-to-get-the-index-of-a-row-when-a-button-in-that-row-is-c

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