Last edited value is not submited

Last edited value is not submited

cr1st1cr1st1 Posts: 14Questions: 5Answers: 0
edited April 2019 in Free community support

Hi!

The editor is defined like this :

editor_comand = new $.fn.dataTable.Editor({
    "fields": [
    {"name": "field1","type": "hidden"},
    {"name": "field2"}],
    table: "#dt_comand"
});

The inline editor is activated like this :

$("#dt_comand").on( "click", "tbody td.editable", function (e) {
editor_comand.inline(this, {onBlur:"submit",submit:"allIfChanged"}); 
});

The problem is :
If i edit for example 3 rows and on the on the 3rd row, after i change the value, i don't press enter and i don't click inside the dataTable wrapper but i click on a button that is outside the dataTable wrapper i notice the the last edited value is missing from $('#dt_comand').DataTable().rows().
If after i edit the last value, i click inside the dataTable wrapper everything works.

My fix is is that i added this code on outside button click event editor_comand.blur();

The blur is not triggered if you click outside the dataTable wrapper.
Also other events like postEdit are not triggered on the last edited value.

My question is :
Do you have other solution than adding editor_comand.blur(); in the click event of the button ?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Hi @cr1st1 ,

    Do you mean something like this? Here, if you edit the second line ('Ashton Cox'), and press the button, it displays the old data still in the console. If so, I think this is a timing issue - the table hasn't been updated yet. I agree it looks wrong - we'll look into it and get back to you. If it's no the problem, please could you update that example to demonstrate your issue.

    Cheers,

    Colin

  • cr1st1cr1st1 Posts: 14Questions: 5Answers: 0

    Hi @colin

    Yes, that's exactly the problem. I will wait for a fix.
    Till then i just execute a blur() before i process any data

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    Answer ✓

    The problem you are running into here is the event ordering. A click on the button bubbles up through the DOM, activating event listeners as it goes. So the first one to activate is on the button itself, then up through the layers onto the document itself, which is where Editor is listening for its click event (since it needs to look for clicks over the whole document to blur the inline editing).

    That's not really something that we can "fix". It might be possible to place an event listener at the top level of the document and filter the element you want, but I think your blur() is more elegant.

    Allan

  • cr1st1cr1st1 Posts: 14Questions: 5Answers: 0

    Thank you

This discussion has been closed.