Avatar of termlimit
Flag for United States of America asked on

JQuery Jeditable Ajax Inline Editing With CakePHP

I created a simple Excel-like table using CakePHP, JQuery, and Jeditable. I have gotten the table to display information just like Excel, some cells are empty while others contain data. I can edit existing cells and can add information to empty cells. The problem though is that when I go to update a cell that was previously new (I clicked an empty cell and typed in 5.00 and hit enter, the data was sent to the server and saved in the database, the cell gets updated, but then realized it was supposed to be 50.00) it only creates new cells. I am using a unique ID for each cell of the table to allow Jeditable to update the cells. The location of each cell is based on a combination of foreign key references, but the value is set through the table.

The problem comes from the fact that I am using an ID that is exploded in PHP to get the values that I need. It is simply value_{ID}_{foreign_id_1}_{foreign_id_2}. With a new entry the {ID} is set to 0. This allows the system to recognize that the entry is new and creates a new value for the cell using the other 2 foreign key values for that location. When the server sends the data back to update the cell, the {ID} remains 0. Even though data exists in the cell now, the cell is still seen as new by Jeditable because {ID} does not get updated.

The question is how can I updated the {ID} of this cell after the save call is made? I have tried every work around I can think of using CakePHP, but can't get it to work. If any one has any ideas I would be appreciative. I have included the code blocks that I am referencing in my text.
<script type="text/javascript">
$(function() {
	$('.click').editable('/controller/action', {
		id        : 'data[Model][id]',
		name      : 'data[Model][amount]',
		type      : 'text',
		tooltip   : 'Click to edit the amount',
		style	  : 'inherit',
		width	  : '90px',
		height	  : '10px'

<td class="click" style="font-size:12px" id="model_<?php echo $detail['id'];?>_<?php echo $category['id'];?>_<?php echo $year;?>-<?php echo sprintf("%02d", $b+1);?>-01"><?php echo $this->Number->currency($row['amount'], 'USD', array('after' => false, 'zero' => '0.00', 'places' => 2)); ?></td>

$detail['id'] is either 0 (new/empty cell) or a positive unique integer (existing data).

Open in new window


Avatar of undefined
Last Comment

8/22/2022 - Mon

$id = $_POST['id'];
$value = $_POST['value'];

if($id && $value)
$query = 'update table set column = \''."$value".'\' where tableid = \''.$id.'\'';
$result = $db->query($query);


You could try the above code

what is the value of ID on the server side you get when u update the data?

The problem is not on the server side. After the server commits the change I have all the server side finished. I need a way to update the client side data (change the 0 to the new id for the cell). The value on the server side is a simple true/false whether it worked or not for the response, so I know whether to return the original cell data or update the cell to the number that was submitted.

When I say id, I don't mean a sql id per say. While the id does correspond to a sql table, the data that needs to be update is the id for the <td> from above <td id="model_0_foo_bar">empty</td>, after submitting the data for the new cell i need the 0 to change to the new id from the table (for example 523), <td id="model_523_foo_bar">empty</td>. I can't figure out a way to update that value in addition to the cell data.

Again the cell will be fine and editable if I refresh, since the <td> gets the new number assigned from the page load.

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.

hmm.. there is irony in this. That is the article I got the original idea from. I didn't understand that part of the script. Let me give that a shot.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.