Search code examples
javascriptjquerydatatablesjeditable

How do I programmatically tell which row to edit in datatables?


I am using datatables:

 $('#purForm').dataTable({
        "bRetrieve": true,
        "bJQueryUI": true,
        "sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
        "bPaginate": false,
        "bAutoWidth": false,
        "bFilter": false

    });

and for making it editable I am using datatables editable plugin:

http://code.google.com/p/jquery-datatables-editable/wiki/EditCell

How it only works when I click on the row's cell. Can I programmatically tell it which row to edit eg. based on some row index of table etc?


Solution

  • I'm guessing that it should be as simple as triggering a click on a table cell.

    eg:

    //first, specify a table cell (as appropriate to your application)
    var $row = $("#myTable tr").eq(2);//third row
    var $cell = $row.find("td").eq(1);//second cell
    
    //then trigger a click
    $cell.trigger('click');
    

    If I'm right, then the cell will now be in edit mode, ready to accept keyboard input.