Programatically position the on-line editor on a cell.

Programatically position the on-line editor on a cell.

gastoncerongastonceron Posts: 4Questions: 2Answers: 0

When using in-line editing, by clicking on a button I can programmatically focus on a particular cell, say row=1, column=2. If I click on that focused cell the editor comes up and I can start editing. I need to start editing without having to click on the cell.
This is my code:

$('#testButton').on("click", function () {
    var row_selector = $('#example').DataTable().row(1);
    var column_selector = $('#example').DataTable().column(2);
    var home_cell = $('#example').DataTable().cell(row_selector, column_selector);
    home_cell.focus(); // this works: it focuses on cell on row 1, column 2
    editor.inline(home_cell); // this does not work, produces an error.
});

This question has accepted answers - jump to:

Answers

  • gastoncerongastonceron Posts: 4Questions: 2Answers: 0

    I found that I can get what I want as follows, but it just seems too dirty to me:

    $('#testButton').on("click", function () {
        $('#example')[0].children[2].children[2].children[2].click();
    });
    
  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Hi @gastonceron ,

    You could just pass in the jQuery node, so row 1 column 2 would be:

    editor.inline($('tbody tr:eq(1) td:eq(2)'))
    

    see example here,

    Cheers,

    Colin

  • gastoncerongastonceron Posts: 4Questions: 2Answers: 0

    Thanks Colin, I like your solution better than mine. However both yours and mine will leave the cursor at the end of the text, like a click on the cell would. Is there any way to emulate a double click on the cell so that the whole text is selected?

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951
    Answer ✓
This discussion has been closed.