Select a row from JS

Select a row from JS

ostmalostmal Posts: 102Questions: 33Answers: 0

I would like to select table row from JS. I do it like here:

var table = $('#myTable').DataTable();
table.row(':eq(0)', { page: 'current' }).select();

But I can't do anything. The row in the table is not selected!

This question has an accepted answers - jump to answer


  • kthorngrenkthorngren Posts: 13,816Questions: 25Answers: 3,252

    Did you add the select library?

    Your example code works here:


  • ostmalostmal Posts: 102Questions: 33Answers: 0
    edited August 11

    I did everything as it should, as in the example that you provided. It doesn't work (
    My test example:

    $(document).ready(function() {
        var Editor = new $.fn.dataTable.Editor( {
            ajax: '/abc_crm/dt/my/edit_err/edit_err.php',
            table: '#edit_err',
            fields: [
                    label: "note:",
                    name: "note",
                    type:  "textarea"
        } );
        var table = $('#edit_err').DataTable( {
            dom: 'rtBp', // Убрал "f" - фильтрациюь
            ajax: {
                url: '/abc_crm/dt/my/edit_err/edit_err.php',
                data: { okr : "58" }
            columns: [
                { data: 'ul' },
                { data: 'note' }
            buttons: [
                { extend: 'create', editor: Editor },
                { extend: 'edit',   editor: Editor},
                { extend: 'remove', editor: Editor }
        } );
        table.row(':eq(0)', { page: 'current' }).select();
    } );
  • allanallan Posts: 54,714Questions: 1Answers: 8,560 Site admin
    Answer ✓

    Since you are Ajax loading the data you need to wait for the data to actually be loaded. At the moment, there is no data in the table when your row().select() call runs.

    You can use initComplete to address that - e.g. in this case:

    initComplete: function () {
      table.row(':eq(0)', { page: 'current' }).select();


  • ostmalostmal Posts: 102Questions: 33Answers: 0

    Allan, everything works fine! Thank you very much!

Sign In or Register to comment.