How to select without clicking?

How to select without clicking?

rusumatrusumat Posts: 10Questions: 5Answers: 1
edited September 2017 in Select

I want to select a row from table without clicking. Instead of $('#myid').addClass('selected'); i want to use jquery like table.rows('#myid').select=true; However i don't know if it is such a use or not. Can you help me?

This question has an accepted answers - jump to answer

Answers

  • ttsettse Posts: 1Questions: 0Answers: 0

    The https://datatables.net/reference/api/row().select()
    does not work.
    var table = $('#myTable').DataTable();
    table.row(0).select();

    I would of expected to select the 1st row of the table and add the selected class to the row, but it did nothing, nada, ziltch :(

  • kthorngrenkthorngren Posts: 6,308Questions: 21Answers: 1,383

    I assume you are loading the select extension as mention in the doc for row().select().

    I think row(0) will select the first row of the data as originally presented to Datatables, before sorting, etc.

    Are you expecting to select the first row displayed? Then you might try the example shown in the docs:
    https://datatables.net/reference/api/row().select()#Example

    Kevin

  • rusumatrusumat Posts: 10Questions: 5Answers: 1
    Answer ✓

    Thank you for your attention. I solved in following way;

    createdRow: function (row, data, dataIndex) {
                var customerrowid = '#' + participantList[dataIndex].CustomerId + 'Cx';
                $(customerrowid).addClass('selected').attr('data-participantlist', 'true').attr('data-addeddatatable', 'true');
                $(customerrowid).find('td:nth-child(1) > input[type="checkbox"]').prop('checked', true);
            }
    
  • karthikkingkarthikking Posts: 1Questions: 0Answers: 0

    I need row select getting row id from binding column values of EmpId

    EmpID Name
    1 John
    2 smith
    4 Mark

    myTable.rows('tr:eq(2)', { page: 'current' }).select(); it is default selecting 2nd row, but i want get row id of EmpID 1,4 and assign into eq(x) of row id, Please help

  • allanallan Posts: 50,303Questions: 1Answers: 7,478 Site admin

    but i want get row id of EmpID 1,4

    Use the row-selector as a function rather than a string. You know the id in the data, so you can check against that in the function.

    If you link to an example on http://live.datatables.net or JSFiddle I can take a look at it.

    Allan

Sign In or Register to comment.