Can't delete rows created with fnAddData()

Can't delete rows created with fnAddData()

piapocopiapoco Posts: 6Questions: 2Answers: 0
edited November 2011 in General
That's correct. I can delete rows hardwired in HTML, but not when the rows have been added with fnAddData(). I've checked everything but to no avail. Please someone help; I don't want to give up on this extraordinary piece of code and go back to run-of-the-mill Javascript. Thanks in advance!

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Can you give us the relevant bit of code please? There should be no reason why fnAddData rows can't be deleted using fnDeleteRow - indeed I've done it in my applications myself.

    Allan
  • piapocopiapoco Posts: 6Questions: 2Answers: 0
    Allan, thanks for your answer. Here's my simplified code; I hope you find an answer for this because I can't wait to see my tables work like a clock. By the way, thanks for making Data Tables public!

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">









    var oTable;
    var giRedraw = false;

    $(document).ready(function() {
    /* Add a click handler to the rows - this could be used as a callback */
    $("#example tr").click(function(event) {
    $(oTable.fnSettings().aoData).each(function (){
    $(this.nTr).removeClass('row_selected');
    });
    $(event.target.parentNode).addClass('row_selected');
    });

    /* Add a click handler for the delete row */
    $('#delete').click( function() {
    var anSelected = fnGetSelected( oTable );
    oTable.fnDeleteRow( anSelected[0] );
    } );

    /* Init the table */
    oTable = $('#example').dataTable( );
    } );


    /* Get the rows which are currently selected */
    function fnGetSelected( oTableLocal )
    {
    var aReturn = new Array();
    var aTrs = oTableLocal.fnGetNodes();

    for ( var i=0 ; i
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    You are only attached events to those HTML elements which are already in the document: http://datatables.net/faqs#events . You want to use live events (or 'on' if you are using jQuery 1.7 - which I see you aren't).

    Here is a working example with live events: http://live.datatables.net/aruwat/2/edit .

    Also Visual Event might be of use to you in future for similar issues as it will show you want elements have events and which don't: http://www.sprymedia.co.uk/article/Visual+Event+2

    Allan
  • piapocopiapoco Posts: 6Questions: 2Answers: 0
    Allan, it's working now. Your code is identical to mine, so I'll have to say that the problem was an old version of Jquery. Now I'm running 1.7.1 and everything is silk smooth. I'll let you know about my website when this piece of code is finished so you can show off your wonderful code. Ha ha ha!

    Thanks a lot again!!
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Sounds great - look forward to seeing your work :-)

    Allan
This discussion has been closed.