Using the EDITOR, Is Inline Editing on multiple tables possible?
Using the EDITOR, Is Inline Editing on multiple tables possible?
I have the following query that I need to use and I want the user to be able to inline edit the SERIAL NUMBER only.
Is this possible?
Here is the query which returns 4 fields:
SELECT
a.kit_inventory_id AS inventoryid,
c.kit_inventory_items_serial_number AS serialnumber,
c.kit_inventory_items_id AS itemid,
d.kit_items_name AS name
FROM kit_inventory a,
kit_inventory_item_history b,
kit_inventory_items c,
kit_items d,
kit_inventory_items_status e
WHERE a.kit_inventory_id = b.kit_inventory_id
AND b.kit_inventory_items_id = c.kit_inventory_items_id
AND c.kit_items_id = d.kit_items_id
AND c.kit_inventory_items_status_id = e.kit_inventory_items_status_id
AND a.kit_inventory_id = ???;
This question has accepted answers - jump to:
Answers
Yes indeed. You would just set it up link a normal Editor, but you must add the primary key value for each of the joined tables that you want to edit. That should be in a
hidden
field type and its just so that the PHP / .NET libraries can identify the joined row to edit uniquely. The primary key is done automatically for the main host table, but not for the joined tables.Allan
Thanks Allan,
Two more things...
Cheers
I'm afraid I don't actually have an example of this available online - although it is something I'm been meaning to blog about for a while! Basically you just need to add the extra
Field::inst()
for the joined primary key and likewise add another (hidden) field in the Editor Javascript. Obviously you won't include it in the DataTable columns.I'm not sure if you can write to a MySQL view can you? It isn't something I've experimented with I'm afraid.
Allan
Thanks Allan, you're right about the views.
My php code is as follows
My JS code is as follows
I'm not sure where and how I am supposed to put in those hidden fields because as it is, I get the following error:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '7-27' for key 'PRIMARY'
Also, I need the ??? to be a dynamic number passed through the URL line:
->where( 'kit_inventory.kit_inventory_id', ??? )
and
Assuming that it is the
kit_items.kit_items_name
field you want to edit. If you have other fields in other join tables that need to be edited (it looks like you do), you would also need the pkey for that table.Allan
One other thing, if you want to use inline editing, you'll need to add
submit: 'allIfChanged'
to the object you pass into theinline()
method as the second parameter (seeform-options
for details).Allan
Thanks Allan, but I tried that and it still isn't updating any records.
Excuse the code below but this comment window isn't properly blocking "code".
Here's my code (I am currently using the "click" event on the "editor.inline" object to limit inline editing ONLY to the "serial number" field, so not sure how or where to put the
submit: 'allIfChanged'.
Updating doesn't work inline or when I edit the row in a modal window.
When I check the JSON response it has the following (first 3 rows):
Notice that ALL rows have the DT_RowId as "row_3".
JAVASCRIPT
PHP
Ass it into the object that you pass in as the second parameter to the
inline()
method - e.g.:Interesting. What is being sent?
Can you give me a link to the page so I can check it out?
Allan
URL removed
When I perform an inline edit, here the POST Params:
Form data
action: "edit"
data[kit_items][kit_items_name]: "Tablet"
data[kit_inventory_items][kit_inventory_items_id]: "27"
data[kit_inventory_items][kit_inventory_items_serial_number]: "123123123"
id: "row_7"
The JSON response shows:
row: Object
DT_RowId: "row_7"
kit_items: Object
Kit_items_name: "Tablet"
kit_inventory_items: Object
kit_inventory_items_id: "27"
kit_inventory_items_serial_number: null
No matter which row I update, the JSON response has DT_RowId = "row_7".
The first row has the name "Tablet" but if I update any other line, it temporarily changes the name on the edited line to "Tablet" as well.
In the page, the PHP is passed a variable of $inventoryid (the same variable in the URL) to be used in the '->where' clause.
Whatever is passed in the where clause is being returned by EVERY row.
Hi Allan,
Finally have it working. It was the way that the query was constructed. I changed the query (PHP code for left joins):
Hi,
Thanks for the updates - great to hear you have it working now.
Allan