Local table editing & calling a sql stored proc to save
Local table editing & calling a sql stored proc to save

I would like to make the editing process so that when they click edit, a forn pops up that will have multiple check boxes or drop downs, a multi select, and comments. when it's saved, it won't actually use the php to update the source bu call a mssql stored proc passing all the values from the form to save back to the db. there maybe multiple updates based on what exactly the user selected in the form. I'm pretty good with sql but been learning datatools. From what I read, using local table editing is possibly what I need to create a space with all of the fields of information used to present to the user for edits. How do I collect the data, construct a string to call a stored proc?
This question has accepted answers - jump to:
Answers
Hi,
You don't need to use the provided server-side libraries for Editor, you can have your own, and that is what I would suggest in this sort of case. The data sent to the server for the Ajax request is fully documented and I'm happy to answer any questions you might have about it. It also shows the data that Editor expects back. What the server does with the data sent and how it gets the data to send back is a black box as far as Editor is concerned. It could go through a quantum computer on the surface of a black hole, with multiple AGIs managing it for all the Javascript cares
.
The idea of that was for exactly this sort of case when you have your own data handling on the server-side that you want to use. The Editor PHP (.NET and Node.js) libraries aren't designed to cover all use cases - the 80/20 rule applies!
Allan
Thank you, I am on a time crunch and did not want to spend time going down the wrong road. Is there any concern if I let the edit post back to the PHP and inspect the action for Edit, then perform the updates there? I had a previous question about reviewing the $_POST and the depth of the arrays, and you suggested using the editor libraries. Am I able to use the editor libraries to get all of the data elements then call the stored procs?
No.
Lol - sorry, I hadn't connected the two threads together in my head.
No - not in the PHP ones (there is a model for it in the .NET libraries, but not PHP).
Okay, so joining the dots now, if you want to use a stored proc. you don't have the option of using the provided libraries for Editor at the moment (one day I'll add support for it, but that isn't in yet).
So you'll need to parse the data that is submitted. It isn't particularly complex data - the
action
is trivial, and thedata
property is nested with the row ids (to allow multirow editing) and the field values - so:You need to know the field names with the above, but presumably you do. You could create an abstraction layer if you want, but if you need to get a crack on, this would be the way to do it.
You need to make sure that the JSON data you return in response to the edit (for the row being edited) is in the same format as the data you used to load the table initially. Normally you've just run it through the same
SELECT
function but with aWHERE
condition applied for the rows in question.What you might find useful with this sort of thing, is to look at the Ajax data tab in an example like this one so you can see what data is being submitted to the server and what is being returned - so you know what your script needs to handle and what to return for the same actions.
Allan
Thank you, you are always very helpful
Allen, a follow up to "You need to make sure that the JSON data you return in response to the edit (for the row being edited) is in the same format as the data you used to load the table initially. Normally you've just run it through the same SELECT function but with a WHERE condition applied for the rows in question.".
Currently I have a datatable whose source is ajax: 'php/Addresses_Address_DT.php' which is using the server side PHP editor to populate.
The datatable has an Edit button which is utilizing addresseditor which also relies on ajax: 'php/Addresses_Address_DT.php' but has additional fields that are not defined in Addresses_Address_DT.php' . When data is saved in the editor, DT will call php/Addresses_Address_DT.php' again. In that code, is it possible I inspect the Action to see that I am saving, perform the necessary SQL updates then afterwards, let the Addresses_Address_DT.php continue to run to return data back to the client side? If so, is there something I need to do in php/Addresses_Address_DT.php to tell it don't worry about trying to update anything, just return data?
Or, do I need to use a different PHP from addresseditor which is doing it's own querying and updating for the specific record I am editing? If this is the case, is there a query I need to do at the end so the client side datatable doesn't get mucked up?
Below are the contents of Addresses_Address_DT.php, note I am hardcoding an AddressAID for now.
If you could show me the client-side code, that would be useful. I'm struggling to understand the full set up at the moment (that might just be me - its been a long few days!).
It sounds like you might be using server-side processing for the DataTable? If that's the case, just have the response to the Editor Ajax call be
{"data":[]}
and then the redraw of the DataTable will fetch the new data from the server.Allan
That's fine, It's client side, the js is below.
Edited by Allan to add syntax highlight
Thank you. So it doesn't have server-side processing enabled. Currently when your Editor form submits it goes to
php/Addresses_Address_DT.php
and it expects back the data for the edited row, per the docs here.I'm not understanding where your stored procedure is coming into this? I don't see it in any of the above code. Is that the problem - you aren't sure where to put it?
If that's the case, you need to have a new PHP file (or an
if
condition in the current one for when data is submitted) which will accept the data submitted by Editor, process it and then return the JSON for the edited rows.Allan