displayed() works only once

displayed() works only once

pisislerpisisler Posts: 106Questions: 21Answers: 1

Per the documentation, displayed() gets the list of fields being currently edited. I deduced that it would display only one field name when inline editing is triggered. And it did. But only for once. For example if you click on "name" filed, displayed() returns "name" correctly, but right after that if you click on "age" for example, it returns an empty object. If you reload the page and click on "age", display() correctly returns "age", while now it returns empty for "name". (Interestingly, some fields sometimes returns when clicked subsequently; but most of the times it returns only the first clicked field name.

Is this by design or a bug?

Answers

  • colincolin Posts: 15,152Questions: 1Answers: 2,587

    It appears to be working as expected here. Could you look at that, please, and see if it helps. If it's still not working for you, please can you update my example, or link to your page, so that we can see the problem.

    Cheers,

    Colin

  • pisislerpisisler Posts: 106Questions: 21Answers: 1

    It says my comment will be displayed after approval

  • pisislerpisisler Posts: 106Questions: 21Answers: 1

    Thank you @collin , your example works perfectly fine and it helped me figure that displayed() will break if called after editor is opened. It needed be called before.

    I see that you used editor.on() event whereas I didn't listen another event while there is already table.on('click') which listens to open the inline editor. Here:

      $('#example').on('click', 'tbody tr td', function() {
        console.log(editor.displayed());
        editor.inline(this);
      });
    

    It works as expected this way. But try replacing the order and place the displayed() before editor.inline(this);. It will return the correct result only once and will break on the next. I edited your example, here it is:

    http://live.datatables.net/wokusawu/2/edit

  • colincolin Posts: 15,152Questions: 1Answers: 2,587

    Ah, yep, there appears to be a timing issue there. If you add a slight delay, it works as expected, see here: http://live.datatables.net/wokusawu/3/edit , so that could be a workaround.

    I've raised it internally (DD-1943 for my reference) and we'll report back here when there's an update.

    Cheers,

    Colin

  • pisislerpisisler Posts: 106Questions: 21Answers: 1

    Thank you again. In my previous post I said "it works expected this way" but actually it didn't. I didn't realize that if you place displayed() before editor opened, it (very normally) returns undefined at first, because editor hasn't yet opened, so nothing is displayed. Then when you click on another cell, it returns the previous field name. Therefore if you place it before editor opened, it won't return anything and the later returned value will never have the current field name but instead it will have the previous one, which is not the expected way. So you always need to call displayed() after editor is opened, which doesn't work currently, without a deliberate delay as you suggested.

  • colincolin Posts: 15,152Questions: 1Answers: 2,587

    Definitely something wonky there - we'll take a look and report back!

    Cheers,

    Colin

This discussion has been closed.