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 Content of Deleted Row Inside onDelete Function #1

Closed
ShawnStrong opened this issue Dec 12, 2017 · 4 comments
Closed

Get Content of Deleted Row Inside onDelete Function #1

ShawnStrong opened this issue Dec 12, 2017 · 4 comments

Comments

@ShawnStrong
Copy link

ShawnStrong commented Dec 12, 2017

Hi there!

I've been using your library to extend the functionality of a table on my website. I figured out how to get the content of a row when a row is edited:

     onEdit: function(columnsEd) {   
          var orgName = columnsEd[0].childNodes[0].innerHTML;
          var contact = columnsEd[0].childNodes[1].innerHTML;
          var number = columnsEd[0].childNodes[2].innerHTML;
          var email = columnsEd[0].childNodes[3].innerHTML;
          var notes = columnsEd[0].childNodes[4].innerHTML;
          editOrg(orgName, contact, number, email, notes);
     }

But, I can't figure out how to get the content of a row when the onDelete function is called:

     onDelete: function() {
            // somehow get content of deleted row
      }

Any help would be appreciated! Thanks.

@t-edson
Copy link
Owner

t-edson commented Dec 13, 2017

Hi.
I must say I don't use Javascript too much and this library was done for using specifically in one project. It's glad to hear is useful for you.
I can see the event OnDelete() doesn't include a parameter. Because it's fired after the row was removed. The best solution for me, is to include a new event called OnBeforeDelete(row) and call it before the deletion.
The changes would be to change the default set to in the line 30 to :

    var defaults = {
        columnsEd: null,    //index td editable, if null all td editables Ex.: "1,2,3,4,5"
        $addButton: null,  //Objeto Jquery del botón Agregar
        onEdit: function() {},   //evento de edición
        onBeforeDelete: function() {}, 
        onDelete: function() {}, //evento de eliminación
        onAdd: function() {}     //evento de agregación
    };

and the function rowElim() in the line 139 to:

function rowElim(but) {  //Elimina la fila actual
    var $row = $(but).parents('tr');  //accede a la fila
    params.onBeforeDelete($row);
    $row.remove();
    params.onDelete();
}

@ShawnStrong
Copy link
Author

Thank you for the quick response. I was able to come up with a solution similar to yours:

function rowElim(but) {  //Elimina la fila actual
    var $row = $(but).parents('tr');  //accede a la fila
    params.onDelete($row);
    $row.remove();
}

and accessing the row's information in the onDelete function in a way similar to onEdit:

onDelete: function(columnsEd) {
    var orgName = columnsEd[0].childNodes[0].innerHTML;
    delOrg(orgName);
}

Thank you for making this library, it allowed me to add a lot of functionality to my table quickly.

@jiaxuml
Copy link

jiaxuml commented Dec 28, 2018

Thank you for the quick response. I was able to come up with a solution similar to yours:

function rowElim(but) {  //Elimina la fila actual
    var $row = $(but).parents('tr');  //accede a la fila
    params.onDelete($row);
    $row.remove();
}

and accessing the row's information in the onDelete function in a way similar to onEdit:

onDelete: function(columnsEd) {
    var orgName = columnsEd[0].childNodes[0].innerHTML;
    delOrg(orgName);
}

Thank you for making this library, it allowed me to add a lot of functionality to my table quickly.

Thank you, your method solved my problem.

@t-edson
Copy link
Owner

t-edson commented Dec 31, 2018

No need to change the code. There is the event "onBeforeDelete", in the last version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants