How to create new row in middle of the data table

How to create new row in middle of the data table

dhanudhanu Posts: 12Questions: 0Answers: 0
edited March 2014 in DataTables 1.8
Now I am able to create new row at end of the data table, but my intentions is evry row has one plus button is there, if user click the button then create next row of the table

Please help

Replies

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    This has come up a number of times already. Just typing your post title into the search box yields lots of relevant results: http://datatables.net/search?cx=004673356914326163298%3Abcgejkcchl4&cof=FORID%3A9&ie=UTF-8&q=How+to+create+new+row+in+middle+of+the+data+table&sa=Search&siteurl=datatables.net%2Fforums%2F&ref=&ss=7j49j2

    Allan
  • dhanudhanu Posts: 12Questions: 0Answers: 0
    Thanks, Allan.
    My question, after adding new row, rows counts are updated in pagination but not visible in table.
    anything missing
  • dhanudhanu Posts: 12Questions: 0Answers: 0
    $(document).ready( function () {

    $("#sellIn").dataTable({

    "sPaginationType": "full_numbers",
    "bPaginate": true,
    "bJQueryUI": true,
    "bAutoWidth": true,
    "bFilter": false,
    "bSort":false,
    //"aaSorting": [[0,'asc']],
    //"aaSortingFixed":[ [0,'asc']], // to force sorting for first column
    "aoColumnDefs": [
    { "bSortable": false, "aTargets": [ 0 ] }
    ]
    //"aaSorting": [[1, 'asc']]
    });

    var oTable = $("#sellIn").dataTable();
    var oSettings = oTable.fnSettings();
    var oData = $('#sellIn').dataTable().fnSettings().aoData;
    var oDisplayMaster = $('#sellIn').dataTable().fnSettings().aiDisplayMaster;
    var oDisplay =$('#sellIn').dataTable().fnSettings().aiDisplayMaster;
    var affectedRowNbr = 1; //childTd.parentNode.parentNode.rowIndex-1;
    var ind = affectedRowNbr+1;
    //var aData = oData[affectedRowNbr]._aData;
    var newRow = " ";
    newRow += "test0test1test2test3test4test5";
    newRow += "";
    //var newRowData = $(newRow)[0];
    var nTr = $(newRow)[0];
    var nTds = nTr.getElementsByTagName("td");
    var aData = [];
    for ( var i=0 ; i
  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    Please link to a test case using JSFiddle, CodePen, http://live.datatables.net or your own site, showing the problem.

    Allan
  • dhanudhanu Posts: 12Questions: 0Answers: 0
    http://live.datatables.net/idinat/1/edit
  • dhanudhanu Posts: 12Questions: 0Answers: 0
    Are you able to see my code
  • dhanudhanu Posts: 12Questions: 0Answers: 0
    http://jsfiddle.net/dhanu/C5z86/
  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    Yes thank you.

    You are modifying DataTables internal variables in the settings object. Modifying these values externally is absolutely not supported. You need to be very careful when doing that, since it will have knockout effects. Also be aware that the settings object can, will and does change between versions.

    If you want a row to be inserted into a specific location in the table, use the ordering options the table provides. That is the only form of row ordering DataTables supports.

    Allan
  • dhanudhanu Posts: 12Questions: 0Answers: 0
    Thanks Allan,
    I tried same as ordering dataTables but not working.
    any other solution is there
  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    No - ordering is the only solution for defining ordering in a DataTable.

    Allan
This discussion has been closed.