How to select top row

How to select top row

abathgateabathgate Posts: 4Questions: 0Answers: 0
edited June 2009 in General
I need a selecttopRow function that is going to work no matter what sort has been applied.

My onclick function getCachedReview is registered like this

$("#example tbody").click(function(event) {
$(oTable.fnSettings().aoData).each(function (){
$(this.nTr).removeClass('row_selected');
});
$(event.target.parentNode).addClass('row_selected');
var anSelected = fnGetSelected( oTable );
var iRow = oTable.fnGetPosition( anSelected[0] );
getCachedReview(iRow) ;

});


Initially I just wanted to select the first row on page load so initially I did this

function load(){
getCachedReview(0);
}

Which, didnt highlight the row and was selecting the last row


So then I tried this
function load(){
var i = ;
getCachedReview(i-1);
}

Which selected the 8th row (again no highlight). So I think a sort is happening and the row index is based on pre-sort.

The table is initialized like this

/* Init the table */
oTable = $('#example').dataTable({
"bPaginate": false,
"bFilter": false,
"bInfo": false,
"aoColumns": [{ "bSortable": false }, null, null, null, null, null],
"bSearchable" : false
}


I need a selecttopRow function that is going to work no matter what sort has been applied.

Help would be appreciated.

Replies

  • allanallan Posts: 63,508Questions: 1Answers: 10,471 Site admin
    edited June 2009
    Hi abathgate,

    It's a bit tricky without knowing what getCachedReview() and the code in whole, but it depends on how you are 'selecting' rows. If you are just adding a class and then this should do:

    [code]
    function selecttopRow( )
    {
    $('#example tbody tr:eq(0)').addClass('selected');
    }
    [/code]
    but if you want to deal with the aoData indexes then you can use:

    [code]
    function selecttopRow( )
    {
    var nTop = $('#example tbody tr')[0];
    var iPos = oTable.fnGetPosition( nTop );
    /* Use iPos to select the row */
    }
    [/code]

    Allan
  • abathgateabathgate Posts: 4Questions: 0Answers: 0
    The second example was what I needed. Thank you. Worked perfectly.
This discussion has been closed.