Why php editor preCreate not working
Why php editor preCreate not working
Hi,
I'm wondering why the preCreate function in Editor part of my php file isn't working !!
I'm using Datatables 1.10 with Editor and server-side process.
After building my editor instance, when I'm trying to make :
->on( 'preCreate', function($editor, $values) {
$editor->db()
->query('update','table')
->set('order_id','uid', false)
->where('order_id','0', "=")
->exec();
})
the row is correctly created on both side (database AND datatable) but the order_id field is still 0.
I tried doing the same thing with postCreate function and it's quite working !
The order_id in the database is equal to the uid as expected but now the event occurs after row creation so the row is on top of the datatable and not on the bottom as it should be. I need to redraw the table to see it where I expected it.
If someone has an idea on how to explain this, it would be very apreciated. Thanks
This question has an accepted answers - jump to answer
Answers
Have you got the
preCreateevent before theprocess()method call? Also, are you using the 1.5.x libraries for Editor (the events were introduced in 1.5.0 - 1.5.4 is the current release at the time of writing).Allan
Hi Allan,
I'm working with the last version : 1.5.4
I have the
preCreatebefore the process() method :I have tried putting it after and the row creation is done but still
0inorder_idon database.Just to clear things up, what I'm trying to achieve is setting the
order_idat the last value of myuidin the database. I'm usinguidin my database as the primary key, so I would have set theorder_idequals to theuidjust after the creation on database but before adding it to datatable (for row ordering).Maybe it's because the row cannot be created with a value that isn't existing already !! But
preCreate:Pre-row creation event - triggered before the row is added to the DataTableso the row should have already been created in the database !!I tried some workarounds like getting the last existing value of
uidororder_idin the database and just add+1to it but it's not working (maybe because of a wrong php code (I'm new with PDO statements))... it's driving me crazy ... :/
Thanks
C.
The documentation in
preCreateis not relevant at all here - that is the Javascript event on the client-side. Ignore that completely - you are using a server-side event here (which happens to share the same name).The documentation you want is in the Editor PHP manual. I think the issue specifically here is that the parameters you are using for
postCreateare not correct.postCreateis passed in four parameters where the second one is the row id that has just been created, which I presume is what you want here.Allan
Ahhh !!! :D
I understand much much much better.
Now, I do the mysql process on php
postCreate:and on the javascript client-side, I reload the table on
postCreate:The
order_idhas theuidvalue and the data is set at the end of the table.Thanks for the link to the documentation I didn't saw. And many thanks for your reactivity !!
C.