简体   繁体   English

在数据后底部的jquery数据表(不是编辑器)中添加空行(用于插入)

[英]Add Empty Row(For Insert) in jquery Datatable (Not Editor) in bottom after data

my question is not how to put the empty row its why the empty row appear as first row我的问题不是如何放置空行它为什么空行显示为第一行

   function BindCenterTable(ID,val) {
        var strSearchLang = " ";
        txtCenetrTotal.value = val;
        if (lang == 'en-US') {
            strSearchLang = "  Search   ";
        }
        $.ajax({
            type: "Post",
            url: 'Query.asmx/FillSubTransCenters',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: '{SubTransID: ' + ID + '}',


            success: function (data) {
                if (typeof CenterTable != 'undefined')
                    CenterTable.destroy();
                CenterTable = $('#tableCenters').DataTable({
                    "aaData": JSON.parse(data.d),
                    "bFilter": true,
                    "bInfo": false,
                    "lengthChange": false,
                    "oLanguage": {
                        "sSearch": strSearchLang
                    },
                    "paging": false,
                    "columns": [
                    { "data": "id" }, { "data": "Center_No" },
                    { "data": "CenterName" }, { "data": "Value" },
                    { "data": "Val_Percent" }
                    ],
                    "columnDefs": [
         {
             "targets": [0],
             "visible": false,
             "searchable": false
         }, {
             "targets": 5,
             "data": null,
             "defaultContent":
              ' <button class="btn btnEdit" type="button"> <i class="fa fa-pencil " style="font-size:20px"></i> </button> <button class="btn btnDelete" type="button"> <i class="fa fa-trash " style="font-size:20px"></i> </button>'

         }
                    ],

                });
                AddCenterEmptyRow();
            },
            error: function (err) {
                // alert(err);
            }
        })
    }



 function AddCenterEmptyRow() {
        var rowNode = CenterTable.row.add({
            "id": "0", "Center_No": "0", "CenterName": "0",
            "Value": "0", "Val_Percent": "0"
        }).draw().node();
        if (rowNode) {
            var jqTds = $('>td', rowNode);
            jqTds[0].innerHTML = '<table style="width:100%"><tr><td><input type="button" id="btnNewCenter"   value="..." ></td><td><input type="text" class="twitterStyleTextbox" style="width:60px" id="txtNewCenter_No" readonly ></td></tr></table>';
            jqTds[1].innerHTML = '<input type="text" class="twitterStyleTextbox" readonly id="txtNewCenterName" >';
            jqTds[2].innerHTML = '<input type="number" style="width:60px" id="txtNewCenterVal" class="twitterStyleTextbox">';
            jqTds[3].innerHTML = '<input type="number" style="width:60px" id="txtNewCenterPerc" class="twitterStyleTextbox">';
            jqTds[4].innerHTML = '<button class="btn btnSubNewCenterSave" type="button"> <i class="fa fa-save " style="font-size:20px"></i> </button> '
        }
        var e = document.getElementById('txtNewCenterVal');
        e.oninput = CenterValChange;
        e.onpropertychange = e.oninput; // for IE8
        var e = document.getElementById('txtNewCenterPerc');
        e.oninput = CenterPercChange;
        e.onpropertychange = e.oninput; // for IE8
        //var e = document.getElementById('txtNewEchange_Rate');
        //e.oninput = DebitChange;
        //e.onpropertychange = e.oninput; // for IE8
    }

every thing works fine but the data appear after the empty row 1-is there a way to select the order where to put the empty row 2- is there a better way for inserting an empty row一切正常,但数据出现在空行 1 之后-是否可以选择放置空行 2 的顺序-是否有更好的方法插入空行

Note : i can not use the footer because it is used for summery but that code is not included注意:我不能使用页脚,因为它用于夏季但不包括该代码

Thank you谢谢

Edit编辑

在此处输入图片说明

According to the creator of Datatables answering a related question :根据 Datatables 的创建者回答相关问题的说法:

The row will be positioned according to the ordering applied to the table.该行将根据应用于表的排序进行定位。 Where ever the table's ordering positions the row, that is where it will appear.表格的排序将行放在何处,它就会出现在哪里。

My solution would be to use the sorting functionality to do this我的解决方案是使用 排序功能来做到这一点

Here is a live example of what i would do...这是我会做的一个活生生的例子......

Hope this helps希望这有帮助

不需要 jquery,只需将它放在 HTML 表的页脚<tfoot></tfoot>中即可。

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

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