fnDeleteRow(anSelected[0]) Returning Undefined

fnDeleteRow(anSelected[0]) Returning Undefined

ahenriksenahenriksen Posts: 2Questions: 0Answers: 0
edited October 2011 in General
I've searched the forums for this and seen examples of others having similar issues but none seem to be calling the fnDeleteRow from within the fnDrawCallback function.

My setup... I've got a DataTable called oTableContacts which has a few rows of data from a MySQL database. I'm not loading the data through the DataTable but rather just spitting it out to a PHP page and then attaching the DataTable to it. Simple stuff so far. Each row has a "Delete" link in it assigned the "delete-contact" class. Clicking on a Delete link fires the click function handler within the fnDrawCallback which then does an AJAX post to the page that handles the delete. All works gravy *except* the darn oTableContacts.fnDeleteRow(anSelected[0]); line. Returns an error "TypeError: 'undefined' is not an object (evaluating 'k.nTr')" in jquery.dataTables.min.js:58. The row is never deleted from the view *but* it is deleted from the database. Any ideas? Much love for any help!

[code]
var giRedraw = false;

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

for ( var i=0 ; i

Replies

  • allanallan Posts: 63,277Questions: 1Answers: 10,424 Site admin
    I don't think you should be putting the click event handler inside fnDrawCallback - that might apply the event handler to the same row multiple times. I would suggest using a live event instead:

    [code]

    var giRedraw = false;

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

    for ( var i=0 ; i
  • ahenriksenahenriksen Posts: 2Questions: 0Answers: 0
    Allan, thank you for your response. Unfortunately I got the same exact error. I would give you a link but it's all on my local dev machine so its not possible. If it helps at all here is my table.

    [code]



    Name
    Property
    Contact Info
     



    <?php foreach($query_contacts as $c_record):?>

    <?php echo $c_record->first_name.' '.$c_record->last_name;?>
    <?php echo $c_record->property_address1;?><?php if (!is_null($c_record->property_address2) && !empty($c_record->property_address2)) { echo '
    '.$c_record->property_address2; } ?>

    <?php if (!is_null($c_record->phone) && !empty($c_record->phone)){ echo ''.image('icons/gray/16x16/phone.png','',array('align' => 'absmiddle')).''.$c_record->phone.''; }?>
    <?php if (!is_null($c_record->mobile) && !empty($c_record->mobile)){ echo ''.image('icons/gray/16x16/fax.png','',array('align' => 'absmiddle')).''.$c_record->fax.''; }?>
    <?php if (!is_null($c_record->home) && !empty($c_record->home)){ echo ''.image('icons/gray/16x16/home.png','',array('align' => 'absmiddle')).''.$c_record->home.''; }?>
    <?php if (!is_null($c_record->mobile) && !empty($c_record->mobile)){ echo ''.image('icons/gray/16x16/cellphone.png','',array('align' => 'absmiddle')).''.$c_record->mobile.''; }?>

    <?php echo image('icons/red/16x16/trash.png','',array('alt' => 'Delete', 'title' => 'Delete')); ?>

    <?php endforeach;?>


    <!-- end tab-contacts -->
    [/code]
This discussion has been closed.