Edit button not working...
Edit button not working...
So I am using your examples which I configured a little to my own datatable. Here is a link to the site:
http://tremblaytest.azurewebsites.net/
I am using your Editor library which I plan to purchase once I know it really works. I have created the new, edit, and delete buttons, and they all work fine, except the "Edit" button. I am returning the proper json object per your docs here:
https://editor.datatables.net/manual/server
For some reason, it does not return any errors and but it does not edit my datatable. What am I doing wrong?
FYI, I am currently not doing anything on the server but returning the appropriate json object since I am only testing your editor. Just in case, here is the server side script:
<?
if(isset($_POST["action"]))
{
$action = $_POST["action"];
if($action == "create")
{
echo json_encode([
"data" => $_POST["data"]
]);
}
elseif($action == "edit")
{
echo json_encode([
"data" => $_POST["data"]
]);
}
else
{
echo json_encode([]);
}
}
Answers
The data returned form the edit is incorrect -
data
should be an array as noted in the documentation you linked to.would do it.
Obviously there are massive security holes with that script. I realise you'll be updating it as you continue your development work, but just incase anyone else reads this and is tempted to copy and paste the above code!
Allan
Wow, talk about some quick response time.
And yea, I tried that, and that actually breaks it completely.
I left the code so you could see and also snapped this picture:
http://i65.tinypic.com/161f5gx.jpg
Also, why would it work for a NEW entry but not an edit. They are practically the exact same json object format....
And yes, no one copy this for production. Testing code only....
So just FYI, I think I solved why this is happening.
I copied my json encoded sting and pasted it directly to my handler file and changed the first brackets of the data object as an array instead of an object, and sure enough, that worked.
IE:
Now, while this works, this is kind of a problem, because no matter what, if I use the function in PHP to json_encode, it will convert any array with a key into an object, which means that this will return an object instead of an array. This is a HUGE inconvenience, simply because now, I will have to essentially remake my array without keys which is just a repetitive step for no reason.
While this solution resolves this issue, I highly recommend that this is fixed the same way that it works for "New" row. For "New" row, I don't have this issue. I would add it to my library and help you code it, but the library is encrypted... Anyway, I would really look into this if I were you. Thank you for the quick response the first time....
I'm really surprised that create and edit behave differently there given that its basically the same code that handle those responses. I will look in to that.
However, regarding your PHP arrays. Can you not simply use
array_values()
to convert the associative array to an indexed array?Allan
So yea, I did further checking, and actually there is no difference to how your Editor works. The difference is how the js posts the data, mainly, on create, it always uses data[0] where as edit results in data[$idOfRow], which somehow, for post, makes this an associative array instead of a non-associative array, which is why the json encode then converts the array into an object....
Your solution of using array_values() does the trick. I do believe that this is a slight inconvenience but will do the trick for now. Perhaps making some specification to your docs for the very specific structure of the results may help and then suggesting an array_values of the post. I suppose if this forum discussion becomes easily searchable this forum should do the trick.
THANK YOU SO MUCH FOR YOUR HELP AND YOU LOOKING INTO THIS! :D