使用JQuery删除数据表行

使用JQuery删除数据表行,jquery,datatable,delete-row,Jquery,Datatable,Delete Row,我有删除datatable行所需的所有代码,但是当我第一次单击该行的按钮时,它会删除标题,而不是我选择的行。删除标题后,它可以正常工作,但我不希望标题可以删除。如何确保标题未被删除 以下是我的文件的代码: @{ ViewBag.Title = "Reissue"; Layout = "~/Views/Shared/_Layout.cshtml"; } <div style="text-align: right; margin-top: 20px; margin-botto

我有删除datatable行所需的所有代码,但是当我第一次单击该行的按钮时,它会删除标题,而不是我选择的行。删除标题后,它可以正常工作,但我不希望标题可以删除。如何确保标题未被删除

以下是我的文件的代码:

@{
    ViewBag.Title = "Reissue";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div style="text-align: right; margin-top: 20px; margin-bottom: 20px; margin-right: 50px;"><button type="button" class="btn btn-primary" id="printBatchButton">PRINT BATCH</button></div>

<div class="container-fluid left">
    <div class="container-fluid left">
        <table id="ReissuesTable" class="table table-striped table-bordered table-hover text-nowrap">
            <thead>
                <tr>
                    <th data-column="CheckNo" class="text-left" id="TDtooltip" data-toggle="tooltip" data-placement="bottom" data-original-title="Check Number" data-container="body">Check No.</th>
                    <th data-column="StudentID" class="text-left" id="TDtooltip" data-toggle="tooltip" data-placement="bottom" data-original-title="Student ID Number" data-container="body">Student ID</th>
                    <th data-column="studentSSN" class="text-left" id="TDtooltip" data-toggle="tooltip" data-placement="bottom" data-original-title="Social Security Number" data-container="body">SSN</th>
                    <th data-column="Payee" class="text-left" id="TDtooltip" data-toggle="tooltip" data-placement="bottom" data-original-title="Payee Name" data-container="body">Payee</th>
                    <th data-column="Date" class="text-left" id="TDtooltip" data-toggle="tooltip" data-placement="bottom" data-original-title="Date" data-container="body">Date</th>
                    <th data-column="Type" class="text-left" id="TDtooltip" data-toggle="tooltip" data-placement="bottom" data-original-title="Type" data-container="body">Type</th>
                    <th data-column="Amount" class="text-left" id="TDtooltip" data-toggle="tooltip" data-placement="bottom" data-original-title="Amount" data-container="body">Amount</th>
                    <th data-column="Status" class="text-left" id="TDtooltip" data-toggle="tooltip" data-placement="bottom" data-original-title="Status" data-container="body">Status</th>
                    <th></th>
                </tr>
            </thead>
        </table>
    </div>
</div>

@section scripts
{
    @Scripts.Render("~/bundles/dataTables")
    <script type="text/javascript">
        $.extend($.fn.dataTable.defaults, {
            'pagingType': 'full_numbers',
            'pageLength': 10,
            'language': {
                'paginate':{
                    'first': '&laquo;',
                    'last': '&raquo;',
                    'previous': '&lsaquo;',
                    'next': '&rsaquo;'
                },
                'info': 'Displaying _START_-_END_ of _TOTAL_',
                'infoEmpty': 'Displaying 0 to 0 of 0',
                'infoFiltered': '',
                'search': '',
                'zeroRecords': 'No matching records found'
            },
            //'dom': '<"top"f>rt<"bottom"<"pull-left"l><"pull-right"i>p<"clear">>',
            'dom': '<"top">rt<"bottom"<"pull-left"l><"pull-right"i>p<"clear">>',
            'initComplete': function (settings, json) {
                $('.dataTables_filter input[type=search]').attr('placeholder', 'Search');
            }
        });

        $(function () {
            var dataTable = $('#ReissuesTable').dataTable({
                'ajax': {
                    type: 'POST',
                    url: '@Url.Action("GetData", "Reissue")',
                    //data: function(d) {
                    //}
                },
                columns: [
                    {
                        data: 'CheckNo',
                        sortable: true,
                        className: "text-center"
                    },
                    {
                        data: 'StudentID',
                        sortable: true,
                        className: "text-center"
                    },
                    {
                        data: 'studentSSN',
                        sortable: true,
                        className: "text-center"
                    },
                    {
                        data: 'Payee',
                        sortable: true,
                        className: "text-center"
                    },
                    {
                        data: 'Date',
                        sortable: true,
                        className: "text-center"
                    },
                    {
                        data: 'Type',
                        sortable: true,
                        className: "text-center"
                    },
                    {
                        data: 'Amount',
                        sortable: true,
                        className: "text-center"
                    },
                    {
                        data: 'Status',
                        sortable: true,
                        className: "text-center"
                    },
                    {
                        data: "actions",
                        render: function (data, type, row) {
                            return '<a class="btn removeBtn" id="return"><i class="fa fa-remove"></i></a>';
                        },
                        sortable: false,
                        className: "text-center"
                    }
                ],
                sort: true,
                ordering: true,
                order: [0, 'StartDate'],
                processing: true,
                serverSide: true
            });

            $(document).ready(function () {
                $('#ReissuesTable tbody').on("click", ".removeBtn", function () {
                    var row = $(this).closest('tr').first();
                    ReissuesTable.deleteRow(row);
                });
            })

            $('[data-toggle="tooptip"]').tooltip({
                delay: 0,
                track: true,
                fade: 100
            });
        });
    </script>
}
@{
ViewBag.Title=“重新发布”;
Layout=“~/Views/Shared/_Layout.cshtml”;
}
打印批
支票号码。
学生证
SSN
受款人
日期
类型
数量
地位
@节脚本
{
@Scripts.Render(“~/bundles/dataTables”)
$.extend($.fn.dataTable.defaults{
“pagingType”:“完整编号”,
“pageLength”:10,
“语言”:{
“分页”:{
‘第一’:‘第一’,
“最后一个”:“最后一个”,
“以前的”:“&lsaqo;”,
“下一步”:“下一步”
},
'信息':'显示总计的开始-'结束',
“infoEmpty”:“显示0中的0到0”,
“信息过滤”:“,
“搜索”:“,
“zeroRecords”:“未找到匹配的记录”
},
//“dom”:“rt”,
“dom”:“rt”,
“initComplete”:函数(设置,json){
$('.dataTables_filter input[type=search]').attr('placeholder','search');
}
});
$(函数(){
var dataTable=$('#ReissuesTable')。dataTable({
“ajax”:{
键入:“POST”,
url:'@url.Action(“获取数据”,“重新发布”),
//数据:功能(d){
//}
},
栏目:[
{
数据:'CheckNo',
可排序:是的,
类名:“文本中心”
},
{
数据:“学生ID”,
可排序:是的,
类名:“文本中心”
},
{
数据:“studentSSN”,
可排序:是的,
类名:“文本中心”
},
{
数据:'收款人',
可排序:是的,
类名:“文本中心”
},
{
数据:“日期”,
可排序:是的,
类名:“文本中心”
},
{
数据:'类型',
可排序:是的,
类名:“文本中心”
},
{
数据:“金额”,
可排序:是的,
类名:“文本中心”
},
{
数据:“状态”,
可排序:是的,
类名:“文本中心”
},
{
数据:“行动”,
呈现:函数(数据、类型、行){
返回“”;
},
可排序:false,
类名:“文本中心”
}
],
排序:对,
顺序:对,
订单:[0,‘开始日期’],
处理:对,
服务器端:是的
});
$(文档).ready(函数(){
$('#ReissuesTable tbody')。在(“单击“,”.removeBtn”,函数()上{
var row=$(this.closest('tr').first();
重新发布。删除行(row);
});
})
$('[data toggle=“tooptip”]')。工具提示({
延迟:0,
轨迹:对,
褪色:100
});
});
}

使用find('tr')而不是具有相同效果的最近('tr')