Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get edited object or id inside onEdit function #12

Closed
AhmMontasser opened this issue Jun 26, 2020 · 3 comments
Closed

Get edited object or id inside onEdit function #12

AhmMontasser opened this issue Jun 26, 2020 · 3 comments
Assignees
Labels
bug Something isn't working documentation Improvements or additions to documentation
Milestone

Comments

@AhmMontasser
Copy link

AhmMontasser commented Jun 26, 2020

Hello Tom,

Thanks a lot for your work.
I was trying to build a custom onEdit function that will save data to the server but didn't find how to reference to the edited data inside the function, is it saved in same variable that I can use ?

I did the initiation as the following
$(document).ready( function () { $('#myTable').DataTable(); var editableTable = new BSTable("myTable",{ editableColumns:"1,2,3,4", onEdit: function() { //what to call here for the edited data? }, onBeforeDelete: function() {}, onDelete: function() {}, onAdd: function() {}, }); editableTable.init(); } );

Regards,

@ghost
Copy link

ghost commented Feb 5, 2021

Hello Tom,

Thanks a lot for your work.
I was trying to build a custom onEdit function that will save data to the server but didn't find how to reference to the edited data inside the function, is it saved in same variable that I can use ?

I did the initiation as the following
$(document).ready( function () { $('#myTable').DataTable(); var editableTable = new BSTable("myTable",{ editableColumns:"1,2,3,4", onEdit: function() { //what to call here for the edited data? }, onBeforeDelete: function() {}, onDelete: function() {}, onAdd: function() {}, }); editableTable.init(); } );

Regards,

do you found any solution?

@CraftingGamerTom CraftingGamerTom added bug Something isn't working documentation Improvements or additions to documentation labels Feb 7, 2021
@CraftingGamerTom
Copy link
Owner

Thanks for reaching out and using bstable! My appologies on a slow response @AhmMontasser , I missed this notification. Thanks for the poke @vipul386 . This was written some time ago so I found I was confused how to access the variables as well. Thanks for bringing it to my attention!

The row that was edited becomes available to your onEdit function when the accept button is clicked (as an element).

I should mention while exploring this I noticed a sort-of bug. Currently the row must be referenced from an array. This will be fixed shortly. Here is an example:

...
onEdit: function($theRowThatWasEdited) {
   console.log($theRowThatWasEdited[0]);
}
...

In the future, it can be accessed like

...
onEdit: function($theRowThatWasEdited) {
   console.log($theRowThatWasEdited);
}
...

I think the long term plan for this project is to move away from jQuery if possible so the element will be returned as a regular JS object. If you need the object in your function as a JQuery object you can run the following code (I removed the '$' to indicate that it is not a JQuery object but it really makes no difference, its just a variable name):

...
onEdit: function(theRowThatWasEdited) {
   let $converted = $(theRowThatWasEdited);
   console.log($converted);
}
...

I hope this helps!

I'll be updating the example code in index.html when the update is rolled out. Thanks for your contributions!

@CraftingGamerTom
Copy link
Owner

I should clarify jQuery will still be used for the foreseeable future. Dont panic based on my previous comment :)

Thanks again for reaching out @AhmMontasser & @vipul386

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants