row().remove() in two buttons

row().remove() in two buttons

lauromnetolauromneto Posts: 129Questions: 0Answers: 0

Good Morning.
I have 2 with this same function:
action: function (e, dt, node, config) {
editor.disable ();
editor
.edit (table.row ({selected: true}) .indexes (), {
title: 'Delete Record',
buttons: ['Delete', {text: 'Close', action: function () {this.close (); }}]
})
.mode ('edit');
editor.set ('clipacstatus', 'E');

}

As at the end of the action of 1 button only I execute row (). Remove ()!?

Replies

  • rf1234rf1234 Posts: 2,949Questions: 87Answers: 416

    Please use Markdown to make your code legible.

    I don't understand your question:

    As at the end of the action of 1 button only I execute row (). Remove ()!?

    What does it mean? Why do you have two buttons with identical functions? What is the business outcome you are trying to achieve? Do you just want to delete a table row? That could be done much easier.

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    I have two buttons with the same action as above.
    I want that, when confirming 1 of these buttons, only in 1, when confirming, the line is removed.

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0
    edited June 2020
    {
    extend: "selected",
    text: 'Delete',
    className: 'btn-red',
    editor: editor,
    action: function (e, dt, node, config) {
    editor.disable ();
    editor
    .edit (table.row ({selected: true}) .indexes (), {
    title: 'Delete Record',
    buttons: ['Delete', {text: 'Close', action: function () {this.close (); }}]
    })
    .mode ('edit');
    editor.set ('clipacstatus', 'E');
    
    }
    },
    {
    extend: "selected",
    text: "Detail",
    className: 'btn-blue',
    editor: editor,
    action: function (e, dt, node, config)
    {
    editor.edit (table.row ({selected: true}) .index (), true);
    editor.disable ();
    e.preventDefault ();
    editor.edit ($ (this) .closest ('tr'), {
    title: 'Record Detail',
    buttons: [{text: 'Close', action: function () {this.close (); }}],
    });
    }
    }
    
  • rf1234rf1234 Posts: 2,949Questions: 87Answers: 416

    I don't understand your code and you don't explain what it is supposed to do.

    I want that, when confirming 1 of these buttons, only in 1, when confirming, the line is removed.

    What does "confirming a button" mean? Clicking on it? Why should the line not be removed clicking the other button? Again: What is your code supposed to do?

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    Friend, the first button should remove the selected line when the editor is closed.
    It is !

  • rf1234rf1234 Posts: 2,949Questions: 87Answers: 416

    use remove() as described in here:
    https://editor.datatables.net/reference/api/remove()
    e.g.:

    row().remove() is not going to work because it is removing a row from a data table which doesn't mean it is automatically deleted on the server, too.
    https://datatables.net/reference/api/row().remove()

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    Friend, I can't use editor.remove, because I'm not deleting the record from the database, I'm just changing a flag on it, note in the code.

    editor
    .edit (table.row ({selected: true}) .indexes (), {
    title: 'Delete Record',
    buttons: ['Delete', {text: 'Close', action: function () {this.close (); }}]
    })
    .mode ('edit');
    editor.set ('clipacstatus', 'E');
    
  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    I need to use this function below, but only when subjected to the action of this button.

    table.row ('. selected').remove().draw(false);

  • rf1234rf1234 Posts: 2,949Questions: 87Answers: 416

    Guess why I keep asking what you are trying to achieve.
    If you just want to remove a row from the data table and not from the data base using Editor you should use row().remove().

    What I don't understand is: Why are you asking these questions instead of trying something like everybody else does? This forum is to help people that have serious problems and are unable to resolve them on their own. Once you've tried a couple of solutions and get stuck: That is the time to ask a question in the forum.

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    If I am asking here it is because I have tried in all the ways that I have known so far (for having been working on this for a short time).
    And I explained several times here that I want this button to change a value of a field in the BD. This is already being done correctly and is working.
    What I want, as I said above, is when submitting the editor that is called by this button, to remove the line! If I use row (). Remove () in the action of this button, it will remove as soon as I click and that is not what I want, I want it to be removed when I submit the editor that is called by this button.
    Understood !?

  • rf1234rf1234 Posts: 2,949Questions: 87Answers: 416

    This was your 7th post. And for the first time you explain in detail what you are trying to achieve. And for me it is going to be the last time that I try to figure out what cryptic questions mean. :smile:

    Here is the Editor event list that is one of the most important things to know:
    https://editor.datatables.net/manual/events

    I want it to be removed when I submit the editor that is called by this button.

    Depending on whether you need a successful submission or not there are two events:
    https://editor.datatables.net/reference/event/postSubmit
    https://editor.datatables.net/reference/event/submitSuccess

    or maybe even this one:
    https://editor.datatables.net/reference/event/preSubmit

    Probably "submitSuccess" is what you are looking for.

    Something like this could work:

    editor
        .on( 'submitSuccess', function( e, json, data, action ) {       
            table.row( {selected: true} ).remove();
        });
    
  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    Yes, it is what I had done and I placed it for you higher than I had already used.
    The fact is, I think you didn't notice it at first, I said I have 2 buttons and I need to do it in 1.
    If I use table.row ({selected: true}) .remove (); on onsubmitSuccess, it will remove the line from all buttons that I submit on the table and that is not what is to be done.

  • rf1234rf1234 Posts: 2,949Questions: 87Answers: 416
    edited June 2020

    Easy: Just define another front end Editor which is similar or even identical and use the event just with one of them. No need to define a second back end Editor.

    Or define a global variable

    var firstButtonClicked = false;
    

    set the variable to true once your "first" button is clicked. And always set it to false once the "second" button is clicked.

    And then:

    editor
        .on( 'submitSuccess', function( e, json, data, action ) {   
            if ( firstButtonClicked ) {   
                table.row( {selected: true} ).remove();
            }
        });
    
  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    I decided this way:

    editor.on ('onSubmitSuccess', function () {
    if (editor.set ('clipacstatus', "E")) {
    table.row ('. selected'). remove (). draw (false);
    }
    });
    

    But, thanks saw raf1234 for the help and patience.
    I'm starting to mess with datatable and I need to understand more.
    But the way I solved it is simpler, you know.

  • rf1234rf1234 Posts: 2,949Questions: 87Answers: 416

    Is that code really working? According to the docs "set()" sets a value but it doesn't get it. And is the Editor form still available on "submitSuccess"? It would still be available on "initSubmit" but I am not sure whether it is available later than that.

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    Yes. The instant I click the button to open the editor, I already send editor.set ('clipacstatus', "E").
    So, on onsubmitSuccess I set this condition. If I am submitting I remove the line in the submit.
    Working 100%

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    Now I'm having a hard time working with dates.
    In my database, date_x is set to date (2020-06-17)
    In the form editor, I need it to appear as 6/17/2020, both in edit and create.
    I don't know how to solve it.
    Colin said to use displayFormat, but I must have done it wrong.

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923

    Colin said to use displayFormat, but I must have done it wrong.

    You should continue this discussion in the thread that colin suggests this.

    Kevin

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    Excuse me....

This discussion has been closed.