Dynamically adding rows is NOT adding on the top of a table.

Dynamically adding rows is NOT adding on the top of a table.

inDiscoverinDiscover Posts: 2Questions: 2Answers: 0

In Jquery Datatable I am trying to add rows dynamically. It is adding dynamically but its NOT adding on the top of the table.

Could any one help please me to add rows dynamically on the top of a table using Jquery Datatable.

Here is the Fiddle http://jsfiddle.net/inDiscover/yo83k3z9/

Inline code

<!DOCTYPE html>
<html>
<head>

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css">


var giCount = 1; jQuery(document).ready( function () { jQuery('#table_id').DataTable(); } ); function fnClickAddRow() { jQuery('#table_id').dataTable().fnAddData( [ giCount+".1", giCount+".2", ] ); giCount++; }

</head>
<body>
<a onClick="fnClickAddRow()">Add Row</a>

Column 1 Column 2

</body>
</html>

Answers

  • janpanjanpan Posts: 19Questions: 4Answers: 0

    Would it be acceptable to just apply sorting ?

    var giCount = 1;
    jQuery(document).ready(function () {
        jQuery('#table_id').DataTable(
            {"order": [[0,'desc']]}
        );
    });
    
    function fnClickAddRow() {
        jQuery('#table_id').dataTable().fnAddData([
        giCount + ".1",
        giCount + ".2", ]);
    
        giCount++;
    }
    
This discussion has been closed.