Enter text into row, hit enter and go to the next row, same column

Enter text into row, hit enter and go to the next row, same column

54696d2054696d20 Posts: 75Questions: 18Answers: 0

Hey. Wondering if you have something already built. I'm using something like https://datatables.net/examples/api/form.html. I have an onchange event that get's the data when changed and passes it to my DB. Instead of clicking on the next text box. I would like it to auto select the next row, same column input box

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,296Questions: 26Answers: 4,768

    I haven't tried it with your specific requirements but may the KeyTable extension will help.

    Kevin

  • 54696d2054696d20 Posts: 75Questions: 18Answers: 0

    @kthorngren kind of. I'm not looking for the focus to be on the next column, but the next row, same column. Like someone hit the tab button. I'm also giving the option to either enter data or scan a barcode into that input.

    Side note: I only have one column you can edit/add

    TIm

  • 54696d2054696d20 Posts: 75Questions: 18Answers: 0

    To add to what I mentioned. I have an onchange event on that input box. So it's triggered on enter or scanned. So I'm researching a way to maybe trigger a keydown event (9).

  • kthorngrenkthorngren Posts: 20,296Questions: 26Answers: 4,768

    Thanks for the clarification. I updated a previous example that might get you started:
    http://live.datatables.net/naxemane/1/edit

    The last two lines in the change event is what you would be interested in. It uses cell().index() to get the current row and column. It uses row + 1 and node() to get the next row's td. Then it uses jQuery to focus the input element of the next row.

    A couple of caveats:
    - Ordering is turned off using order: []. Ordering complicates getting the next row.
    - There is no checking for the last row in the table. You may want to see if nextCell is undefined to handle this situation.

    If this doesn't help maybe you can build a simple example so we can help with your specific solution config.

    Kevin

  • 54696d2054696d20 Posts: 75Questions: 18Answers: 0
  • kthorngrenkthorngren Posts: 20,296Questions: 26Answers: 4,768
    Answer ✓

    Your onchange function call is not found. Instead of troubleshooting that I updated my example to simply use jQuery to move the focus to the next row.
    http://live.datatables.net/qosejica/1/edit

    I get the column index using the same API as before but then use jQuery to focus the input of the same column in the next row. This seems to work with ordering. However if you order your Barcode column then the focus might not be the next row after ordering takes place. Might be confusing for the user.

    Kevin

  • 54696d2054696d20 Posts: 75Questions: 18Answers: 0
    edited January 2019

    Oh it's there. Didn't test on why it doesn't work. But with your example. I was able to come up with (this example looks for what table it came from)
    http://live.datatables.net/yeqazuze/29

    Thanks

  • StevenKuoStevenKuo Posts: 1Questions: 0Answers: 0

    Hi,

    I tried the code with
    http://live.datatables.net/naxemane/1/edit

    It's works well on first 3 rows, but other rows dose not work.

    ex. when I tried on row 4, it will jump to row 16.

    May I know if any things I missed ?

    thanks

This discussion has been closed.