Friday, January 2, 2009

Adding table row with AJAX

Hi,
I thought I had posted this question the other day but cant seem to
find it on a search of the list so I will try again.

In my 'add' view I have a form. Part of that form contains a table
that has 4 inputs in a single row. This row is rendered from an
element (/views/elements/ingredient_row.ctp). Underneath the table
there is a button to add another row of inputs to the table.

Here is the button:
echo $ajax->link('Click Here', 'edit/', array('complete' =>
'add_ingredient_row()'));


Before I go further I want you to know that I have read the docs and I
gotten the simple AJAX stuff to work successfully to update a DIV or
some other content on the page. I have also scoured this list and done
searching on the net looking for some clues but have not found
anything that addresses my question of appending data to a table.

My assumption is that I will have to append the returned row to the
table myself using the add_ingredient_row() javascript function that I
specified be called upon completion of the request. Is this correct?

If that is correct how do I get the data into the function?

Is there is a simpler CakePHP way to append rows to a table?

If there is something that actually addresses this in the manual could
you please point it out to me. It really feels like I am missing
something obvious and will kick my self when its pointed out.


In addition I was looking at the API to see if I could figure out some
options for the ajax->link method. So I tried the following:

EDIT.CTP

<h2>Testing AJAX with CakePHP and Prototype and Scriptaculous</h2>

<table id="mytable">
<tr id="row1">
<td>Row1</td>
</tr>
</table>

<div id="mydiv">
This is a div
</div>

<?php
echo $ajax->link('Click Here', 'edit/', array('append' =>
'mytable'));
?>

EDIT ACTION IN CONTROLLER

function edit()
{
$this->pageTitle = 'Edit Page';
if($this->RequestHandler->isAjax())
{
echo '<tr><td>This is a row</td></tr>';
}
}

This actually returns the data but does not append it to the table. I
know its returning because I see it in the response using Firebug.

Thanks for any help.
Steve

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: