How to change bubble-edit to insert, after row created with rows.add()
How to change bubble-edit to insert, after row created with rows.add()
So, I have a list of Guests. I know the list is, say, 3 guests long.
My database only has 1 guest, as the other 2 have not been added yet (don't want to create dummy's in DB when I find out total is 3).
I load my DataTable from the Guest list containing one row, then I use rows.add() to create the fake data for the 2 missing rows and display to the user as RealGuest, Guest #2, Guest #3.
Now, the user can bubble-edit the first row just fine. I want them to be able to bubble edit rows 2 and 3 also (both having GuestID=0, so both being row_0 possibly, which may be an issue I just realized). When they bubble edit an added row for the first time, then the row will be created with all the dummy data and their one real-data edit from the bubble.
Things I have tried:
preSubmit - Fires all the time, but has strange random fields none of them being Guest ID
preEdit - Fires for exsiting DB rows, doesn't even fire for the added rows, but editor json still sent.
Editor JSON always action='edit', always includes edited field and some other random fields with blanks (why?)
This is what I thought would work, and I still think would work... if preEdit was triggered for the added rows.
editor.on('preEdit', function (e, json, data, id) {
if (id==0) {e.mode('create');} //is it really this easy?
} );
In general, after using rows.add() and giving a datatable extra rows... how would one then update the DB using editor? I have searched but found no answer. Thanks in advance for your always awesome support.
This question has an accepted answers - jump to answer
Answers
NOTE: This is what I mean by random fields:
AI-TITLE: ""
DD-TITLE: ""
Guest_BirthDate: ""
Guest_Created: ""
Guest_DisplayName: "hjgj"
Guest_Modified: ""
Guest_Status: "New"
OD-TITLE: ""
TOP-TITLE: ""
...there are many more fields, and all fields are sent to editor always. DisplayName was edited, and I guess all the TITLE's show up there, but why BirthDate (which is blank) and why Created/Modified (which should not be blank for the existing real row, but are in the preSubmit along with missing a ton including Guest_ID)
NOTE 2: None of the above is important, just find me any way at all to intercept an Editor bubble-edit, and first create a row if it doesn't exists and then perform the bubble edit on the newly created ID (tricky?). I can use any ID's/data you like in creating the fake-rows using rows().add(), passing all the fields, same as the JSON that ran before it. Maybe I need to use Guest_ID = lastRealID+1 for the fake one ahead of time, as well as lastResID+2, instead of using Guest_ID=0 for both (Guest_ID is an auto-increment field, however, you can add a guest to an old reservation so they would have a much higher ID when created, so that wouldn't work)
NEW EXPERIMENT: I found the random fields drop off when I unlink the table (removed table: from editor create). The title plugin fields remain, as well as the one field edited. Note: I don't need the table linked, as the table data actually comes from a view of many tables, and each bubble edit is declared calling the appropriate editor and passing it ALL the fields for that particular table. A side effect is without it linked it I need to manually update the table, but worth it to have multiple editors with multiple-field bubbles in different columns across multiple DB tables that make up the view.
Anyway, the above is not a solution, because Guest_ID is still not a field in preSubmit, and preEdit doesn't fire at all, not even for existing rows with a valid Guest_ID, when the table: is not used in the editor creation.
Could you give me a link to your page so I can walk through it please? Certailny having overlapping IDs is going to be a problem.
Bubble edit should only be possible on rows which already exist. It can't be used to create new rows. You've created rows using
rows.add()
which is fine, that are "real" rows and should be editable as normal.Thanks,
Allan
Hey Allan, thanks for the reply.
While datatable.rows().add() does add a "real" row to DataTables, it does not make any AJAX call to update the database's real rows.
I'm trying to use Bubble edit to create a row, in the same manner that you use Edit to duplicate a row in one of your examples (you just set e.mode('create'); and it is magic).
My goal is to add "fake" rows to the DataTable (already works) without updating the database (it already doesn't) and then if an field of the row is edited (with bubble editor, or full editor, or inline, or whatever) I want to to insert a row, using all the "fake" row data that was provided in rows().add(), plus the update to whatever field was edited.
I will PM you with login information to my site so you can see it in person.
DataTable PHP code:
...where FrontDesk_Popups_ResGuests is a VIEW containing many complex table joins, but the primary table is Hotel_Guests
Editor PHP code:
Bubble-Edit code:
Might as well post the final parts too...
DataTable:
Editor:
I should have posted the entire render function above. Here it is now:
Many thanks - I've sent a reply via PM
Allan
I just wanted to follow up on my post. FYI: I was able to get it to work, using bubble edit with mode="create". If anyone needs help with that, feel free to PM me.
I do have one last issue... I need to updater the Editor AJAX, but can't get it to work. Anyone got any ideas?
The issue is the ResID can change without reloading the page, and I need to send ResID to Editor even though it is not part of the table (it is for a secondary lookup table that links Guests to Reservations)
I have tried something like this, but no luck yet:
I've just sent a reply by PM - sorry for the delay there. For completeness, I've copied my response here:
That isn't working because your original ajax option for Editor doesn't have a url property - it is actually a string itself:
So ajax() is just returning that original string and then the .url is adding a new property to it!
What to do here is for the initialisation have:
then your line of code will work.
Even better I would say though is to use ajax.data as a function and append the data to the query being sent to the server:
Note that submits in the query body not the query parameters.
Allan
Great. I will use ajax with the url and data-function parameters.
One question... how do I then access it in the PHP lib?
...replace this with what?
$resid = $_REQUEST['res']
Nevermind, I see in your PM you said $_POST should get it (so $_REQUEST should probably still work too).
Also per your PM, I will try enabling bubble to submit all fields instead of only changed fields, and then I will be able to get the data I need from that instead of "s"
I will report back with all the final code once this is done, in case it ever helps anyone else.