Custom Buttons
Custom Buttons
Description of problem: I have a two step editing process. The user can edit rows in the table as they wish. When they have finished editing a row and want to synch that row to the cloud repository, they can click a synch button instead of the regular Save button. I have figured out how to create a custom button and I have the event object when clicked, but I can't seem to identify which row is being edited when the button is pressed.
Would it be better to create a field in the table that they could check when they are ready for the data to be sent to the cloud?
This question has an accepted answers - jump to answer
Answers
See if this Delegated events example helps. If not please post the code you are trying to use for this so we can see what you are attempting.
Kevin
I tried using the code and couldn't get the data. On my datatable, I have a Edit Pencil button that the user clicks to open a custom form template editing window. I have two buttons, Synch and Update. The Update event works to update the data in the HTML form. I also can get the event from the Synch button click. I have used:
table.rows({selected}).data() and table.rows(this).data() to get the data and what is returned is a large object named B. If I use the example to assign a variable data to the table.rows(this).data() and then use data[0] or data[1], I get undefined.
I'm guessing the problem is you are trying to use
data[0]
, which is for arrays, but you have objects. So you will want to address the particular objects you want. Again if you need further help please post the code you are trying, along with the Datatables init code. This will help us understand what you have. Better is a link to your page are a test case replicating the issue so we can help debug.https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Here is my GetCatalog() function. It draws the table and editor and creates event handlers:
there is a lot of console.log entries so I can see what is present
What part if this code is not working as expected? Without no test case its difficult to understand the logic and expectations when a lot of code is posted. Please provide details, line numbers, if wat you are trying to do, what the actual result is and what you are expecting to be different.
Kevin
The part I am having problems with is the code below. I am creating a custom button on the custom form template. When clicked, it executes the action part. I am attempting to get access to the data for the results of the edit.
When the Update button is selected, I call this.submit() and that then executes the
function. That has worked. What the Sync button should do is set a flag so I can execute another method that sends the data to the cloud.
I don't know how to illustrate that any more than I have.
This helps. As you can imagine its difficult, with all the Datatables and Editor options available to dig through over 200 lines of code to try and understand someone else's solution
I'm not an Editor expert but my understanding is the
action
objectbuttons()
API usesthis
to provide access to the Editor API. Maybe you can useget()
to get the row data then send it to the cloud.Additionally with the
submit()
method you might want to keep the form open after the submit. Also you might optionally want to disable the syn button until the edited data has been successfully submitted.I built a simple example to demo this with your code example:
http://live.datatables.net/guwafemu/309/edit
Just click on the Name column to bring up the form.
Someone else may post a better way of doing this.
Kevin
the this.get() method actually returned all of the form data. I did not know about that method. Thanks. This gives me all the data I need to send it to the cloud. I appreciate all your help.