Editor Create and Edit Same Time
Editor Create and Edit Same Time
Hello,
Is it possible to create new record and edit old record on the same time?
I want to record edit process. When a user edit a record, it will create new record, and the edited record will marked as edited.
I'm using create button with default value triggered from selected row. After a user press the create button, new record will added based on old data. (This already done)
In the same time, the old data will update edited column as yes (Need help on this)
Please advise, thank you
Replies
In the same table, or logging the new record to a different table based on the data submitted?
Allan
in the same table Allan
Thanks for the clarification - that isn't something that Editor currently supports I'm afraid. You can use the server-side events to have it create a new record (which I guess you've already done), but there is no option to have Editor read that extra new row and return it.
You could potentially use the
Editor->data()
method to get the data that would be returned in the JSON and then add the extra row to thedata
property - I think that Editor should then add the extra row due to its multi-row editing support, but that isn't something I've explicitly tested for.If that doesn't work you'd need to reload the table's data (
ajax.reload()
) in asubmitComplete
event handler.Allan
Hi Allan,
Thank you for your information. I don't really understand with your suggestion. Is it possible to use something like this?
Get the old id on select, then pass it to tes.php SQL UPDATE
I'm trying those, but no luck. Please advise, thank you
Basically that - yes. Lines 2 and 3 shouldn't be required (indeed, they aren't valid Javascript). Just a call to
ajax.reload()
will reload the table in its current state.Allan
Hello Allan,
I'm using line 2 to get the detail_id (primary key) for the old data row, that i want to edit.
I mean, after create new record with the basic editor, I'm trying to use manual SQL Updated using file tes.php and pass the var detail_id to $php detail_id
So i'm thinking to use the submitSuccess event to manual edit the old row using the code above.
My tes.php is:
note: changes=1 means the old record set to edit
Unfortunately not working. Please help, thank you
Danny
Can you give me a link to the page so I can take a look at what is going on and help to debug the issue please.
Allan
Please visit this link
on that example, ID #3 is a new record from #1 (see old ID column), which created from transfer button (using the create function on editor)
what i want is after
submitSuccess
, the changes column on ID #1 will edited to 1 (which means edited)So i'm trying to update the changes column using code above.
Please assist, thank you
Danny
Hi Danny,
Rather than using another Ajax request to increase the Changes count, I would suggest using a server-side event -
postCreate
in this case. That will let you run yourUPDATE
method in the same request that Editor makes to create the new row.When the
ajax.reload()
call really should be as simple as:Allan
Hi Allan,
Following your suggestion and a little search, I found this link and tring to adapt to my case by adding this code
but still not working.
Response:
Please help, thank you
Danny
That is making the returned data invalid JSON. Are you able to remove that?
Allan
i think if comes from var_export( $id )
after i remove that line, it's working, but stil not updating the old row. the changes field is not set to 1.
Please help, thank you
Hi Danny,
Thanks for the clarification. So my understanding of what should be happening is that your
postCreate
function in PHP should be updating thechanges
column in the database. First question: is it?Then, there should be a
submitSuccess
event handler, like the one I suggested above, on the client-side that will cause the table to reload with the new data. Second question: Is that event handler present, and is it executing?Allan
Hi Allan,
I already put this code as your suggestion
I think my problem is coming from MySQL that not updated.
If i checked the MySQL Table,
changes
column still 0, not updated to 1Please see this image
Blue circle should be '1'
thank you
Does the browser's developer tools show that the data for the table is being reloaded?
If you access the database directly, does it show if
changes
has been altered?Is
'tr_receiving_detail1.id === "tr_receiving_detail1.old_id"
what is required? I suspect you actually need:See the documentation here.
Allan
As your suggestion, i'm changing my code to this one, but no luck. the
changes
won't altered.I don't really understand with your question
But I looked into the Developer's Response, after the create button pressed, there are 2 transfer.php
I think the table is reloaded, but the
changes
column still not updated. What i want isSQL
UPDATE `tr_receiving_detail1` SET `changes`=1 WHERE 'tr_receiving_detail1.id' = 'tr_receiving_detail1.old_id
How to check that the
postCreate
is loaded ?Good - that's what I was after. Thanks. That means the client-side part is correct. The issue is the SQL update.
In PHP you would need to add some trace information. A simple
echo "Hello";
would do it (it would mean that your JSON return is invalid, but that's okay for a quick test!).If you open
Database/Drivers/Mysql/Query.php
you'll find a commented outfile_put_contents
line. Could you remove the comment so it enables that line and update the output path to suit your server. When trigger the action and view the contents of the file, it will show the SQL commands that Editor used. Can you show me them please?Allan
here's the result Allan, please take a look, thank you
Thank you. It shows:
which looks correct for what you intend.
If that isn't setting the value to
1
it can only mean that the condition isn't working. It does seem like a slightly odd condition that theold_id
would be equal to theid
(which I presume is the primary key).If, in that function you code:
what do you get?
Allan
Error on line 66
query:
continue below, text too long
part2
What was the error please?
ah sorry forget to put the error
here's
<b>Fatal error</b>: Call to undefined method DataTables\Database\DriverMysqlResult::where() in <b>../function/tr-transfer.php</b> on line <b>66</b><br />
Sorry! Could you try this:
Thanks,
Allan
Here's the response
Here's the editor_sql
Thanks! If the result set it empty it means that there are no rows that meet the applies condition.
I'm still surprised that the condition is
id = old_id
. What is settingold_id
?Allan
i'm using
old_id
to refer the new row to the old row.for example:
on row # 9,
id = 9
,old_id = 2
meaning row # 9 is an edited record from id # 2
id # 2 will no longer used, and must marked as
changes=1
, and replaced by id # 9my scenario:
- i'm creating new record, using default value from
old_id
row (which already done) and- update the
changes
field onold_id
row, in a moment aftersubmitSuccess
(which not done yet)all in 1 button process
please advise, thank you
Thank you for the explanation - that was exceptionally useful and I believe let's me help to resolve the issue. Try using
That uses the value submitted as the old_id as the value to use in the condition.
Allan
Hello Allan,
unfortunately, there are still error
Line 77:
editor_sql:
i'm trying to echo
$_POST['tr_receiving_detail1']['old_id'])
, no resultplease help, thank you
Sorry,
$_POST['tr_receiving_detail1']['old_id']
should have been:Allan