Insert a new row into DataTable

后端 未结 4 424
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-13 17:12

I have a datatable filled with staff data like..

Staff 1 - Day 1 - Total
Staff 1 - Day 2 - Total
Staff 1 - Day 3 - Total
Staff 2 - Day 1 - Total
Staff 2 - Da         


        
4条回答
  •  北海茫月
    2020-12-13 17:49

    You can do this, I am using

    DataTable 1.10.5

    using this code:

    var versionNo = $.fn.dataTable.version;
    alert(versionNo);
    

    This is how I insert new record on my DataTable using row.add (My table has 10 columns), which can also includes HTML tag elements:

    function fncInsertNew() {
                var table = $('#tblRecord').DataTable();
    
                table.row.add([
                        "Tiger Nixon",
                        "System Architect",
                        "$3,120",
                        "2011/04/25",
                        "Edinburgh",
                        "5421",
                        "Tiger Nixon",
                        "System Architect",
                        "$3,120",
                        "

    Hello

    " ]).draw(); }

    For multiple inserts at the same time, use rows.add instead:

    var table = $('#tblRecord').DataTable();
    
    table.rows.add( [ {
            "Tiger Nixon",
            "System Architect",
            "$3,120",
            "2011/04/25",
            "Edinburgh",
            "5421"
        }, {
            "Garrett Winters",
            "Director",
            "$5,300",
            "2011/07/25",
            "Edinburgh",
            "8422"
        }]).draw();
    

提交回复
热议问题