Adding Rows

Adding Rows

psionpsion Posts: 5Questions: 0Answers: 0
edited May 2012 in General
I have been searching but haven't found the exact solution to this. Is there a way to add new rows to the DataTable at the top instead of the bottom or is there a row to automatically scroll to the row that has been added?

My DataTable has no pagination.

thanks

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Rows are inserted at the point they are would be at according to the ordering applied to the table - so if you want to put them at the top you need to make sure the ordering would shift them to the top.

    Regarding scrolling to the row - I don't have a function to hand that would do that, but the principle is shown in this plug-in: http://datatables.net/plug-ins/api#fnAddDataAndDisplay . fnAddData gives you the information back that you need to address the new row - you can use standard jQuery methods to scroll to that node.

    Allan
  • psionpsion Posts: 5Questions: 0Answers: 0
    thanks, Alan. while I'm at it, each time I add a row, I would like to make that row 'edit-able'.
    something like this, I think.

    [code]
    var obj = gObjTable.fnAddData([checkbox, name, acc, currentBalance, payment, balance, checkNo, status, pid, hasLateFees]);
    var oSettings = gObjTable.fnSettings();
    var nTr = oSettings.aoData[obj[0]].nTr;

    $('select the Nth TD of the nTr object') .editable(......);

    [/code]

    is that what it is? I'm having a bit a of difficulty selecting the from that nTr object.
  • psionpsion Posts: 5Questions: 0Answers: 0
    also, what do you mean by "according to the ordering applied to the table"? I can set the table order? how?
  • psionpsion Posts: 5Questions: 0Answers: 0
    Never mind, Allen. I realized I've done something similar in my app. For those interested in this: My solution was to use the "fnCreatedRow" event and added the following:

    [code]
    "fnCreatedRow" : function(nRow, aData, iDataInde)
    {
    //4 is the index of the column i'm interested in. I only wanted to make ONE column editable.
    $('td:eq(4)', nRow).editable(function (value, settings){ ....... }
    }
    [/code]
This discussion has been closed.