Can I get the editor to automatically select a newly added row in the table?

Can I get the editor to automatically select a newly added row in the table?

tchristforttchristfort Posts: 22Questions: 7Answers: 0

I tried the postSubmit event, but at this time the new row is not added to the table so the last row is just before the newly inserted. Is there an event called when a new row is added to a table I could use?

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    The best bet would be to use postCreate at this point, as the row would have been added to the table by that point. See example here,

    Colin

  • tchristforttchristfort Posts: 22Questions: 7Answers: 0

    Thanks Colin,

    I tried to add the postCreate trigger. The trigger fired correctly, however the console.log statement said 'undefined' to the id paramter. I'm using DataTables-1.10.16

    Any idea what is wrong?

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736

    Its hard to say what the problem might be without seeing it. At minimum you can post your code here. Better is a link to your page or a test case replicating the issue so we can see what you have.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    You can use the browser's debugger to evaluate the statement to find out what is actually is actually undefined.

    Kevin

  • tchristforttchristfort Posts: 22Questions: 7Answers: 0

    It is difficult to create a test case as closely integrated with server side mysql processing. I have added this code:

    editor.on('postCreate', function(e, json, data, id) {
    console.log(id);
    table.row('#'+id).select();
    });

    If I console.log e, json and data these are definded, however id is not defined in the function.

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736

    According to the postCreate docs:

    Since 1.8: ID of the row / object being created. Can be used to query the DataTables API for the row (e.g. get the node).

    What version of Editor do you have?

    Your code works in this example:
    http://live.datatables.net/guwafemu/125/edit

    Kevin

  • tchristforttchristfort Posts: 22Questions: 7Answers: 0

    Sorry for late reply, my data tables is 1.10.16, but now see that the Editor folder say: Editor-PHP-1.7.2 so that may be the problem.

    Do I need to update both DataTables and Editor?

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    It would be best to keep them in sync, so yep, best to update both,

    Colin

This discussion has been closed.