AJAX button on table rows to delete rows I have a standard form with a table. I can add lines to the table via AJAX.
I also like to delete the lines using AJAX. But I don't know exactly where and how to add the buttons.

Here is my code to build the table inside the standard form building function:

  ...
  $aPersonsTable = array();
  foreach ($aPersons as $key =&gt; $value) {
    $row = array($value['dname'],'HERE IS THE PLACE WHERE THE BUTTON SHOULD SHOW UP');
    $aPersonsTable[]=$row;
  }

  $form['persons']['ptable'] = array(
    '#theme' =&gt; 'table',
    '#header' =&gt; $pheader,
    '#rows' =&gt; isset($aPersonsTable)?$aPersonsTable:null,
    '#disabled' =&gt; TRUE,
    '#title' =&gt; 'Users currently assigned',
    '#empty' =&gt; t('No users assigned yet!'),
    '#prefix' =&gt; '&lt;div id="ptable_wrapper"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
  );
  ...


I'd like to have the button at 'HERE IS THE PLACE WHERE THE BUTTON SHOULD SHOW UP' :-)

I tried something like:

$row = array($value['dname'],array(
  '#type' =&gt; 'submit',
  '#value'=&gt; 'Delete person',
  '#attributes' =&gt; array('id'=&gt;$value['id']),
  '#ajax'=&gt; array(
    'callback' =&gt; 'delete_person_ajax_callback',
  )
));


Any ideas?
I googled and stackexchanged a lot, but did not find the right solution.
Thx.
I found the answer using drupal_render(). The buttons are now generated in each row, havin their own ids, so that I can read the triggering element in the callback function.
Now I only have the problem whe I click one of the buttons, the complete form is submitted. There seems to be no ajax callback. I will search further an will the edit the answer...

  foreach (aPersons as $key =&gt; $value) {
    $form_button['button'] = array(
      '#id' =&gt; 'del_'.$key,
      '#type' =&gt; 'button',
      '#value' =&gt; 'Delete',
      '#ajax' =&gt; array(
        'callback' =&gt; 'delete_person_ajax_callback',
      )
    );
    $deleteButton = drupal_render($form_button['button']);
    $row = array($value['dname'],$deleteButton);
    $aPersonsTable[]=$row;
  }