Row added not shown
Row added not shown
Hi Allan
Versions : Editor v1.4.2 + DataTables 1.10.7
I add a row and it isn,t shown till I press F5
I have serverSide parameter to false. If I change serverSide to true it works but I would keep serverSide = false.
Before I used DataTables 1.9+ and Editor 1.2.3 and it worked.
This discussion has been closed.
Replies
Hi,
Are you using the Editor PHP libraries? If so, could you use your browser's developer console to check what is being returned fraom the Ajax call that Editor makes when creating the new row. It should be JSON data that describes the newly created row.
Allan
Yes I use Editor php libraries
create.php returns {"row":null}
This is my create.php :
include( "partes.php" );
$editor->process($_POST)
->json();
Okay, if it is returning
row: null
then it means that when the libraries try to read the newly inserted row back from the database, they can't.Most commonly that is because of a
where
condition that prevents it from being read. Might that be the case here?Allan
No.
I presume that is the
partes.php
file and it then immediately goes on to process the input data and return the JSON to the client side?What database are you using?
I assume that
cliid
is not a parameter that is submitted as part of the Editor form? That would seem to be the one stand out point for me.There is something that is stopping Editor from being able to read the row back after it has been written to the database - that is what the
row:null
means. We need to figure out what is causing that.Allan
I,m using MYSQL
I gonna give you a more simple example in my application that doesn,t work.
File create.php :
File tipos.php
Call :
Does it work if you remove
Field::inst( 'id' )->set(false)
? Are you showing the primary key in your table?Allan
Yes I,m showing. It,s an autoincrement field.
If I remove it works.
But I want to show it in my datatables and my editor. Before I update to the last version of datatables it worked.Is there any way to solution this?
This is a key point that I didn't realise before. So you have the primary key in your Editor editing form? Is it readonly?
There are a few options available:
->set( false )
it might actually work as expected.preSubmit
to remove thedata.id
parameter from the submitted data (delete json.data['id'];
).The issue is being caused by the fact that newer versions of Editor allow the primary key to be edited (personally I think that is almost always a very bad idea, but there were a few use cases whereby it was required for others, which is why that is included now).
The test Editor uses is to check if the primary key is in the submitted data - this is possibly a little flawed. It should perhaps check if the field is read only as well. I will look at adding that check for 1.5.
Regards,
Allan
Only works to me with option 2.
But I will thank you if you solve it, in order that I can see the primary key in Editor (readonly, disabled, ....)
Hi,
I've just committed the change required to have this work as expected, which will be available in Editor 1.5. In the meantime, if you want to apply the change required to the 1.4.2 libraries there are two places where a change is required:
1) In the
_create
method - search for the comment "// Was the primary key sent and set? Unusual, but it is possible" and replace the block of code immediately following it with:2) In the
_update
method search for the comment "// Was the primary key altered as part of the edit? Unusual, but it is" and replace with vlock of code immediately following it with:That will ensure that Editor doesn't get itself confused if the primary key value is submitted, but not used.
Thanks for letting me know about this one!
Allan
Hi
I modify that and I get an error " Undefined variable: values on line ..." in this two lines:
"if ( $pkeyField && $pkeyField->apply( 'edit', $values ) ) { ..."
and " $getId = $pkeyField && $pkeyField->apply( 'edit', $values ) ? ... "
Oh bother - yes, sorry. Replace
$values
with$this->_formData
in both cases and that should do it.Allan