fnGetSelected() after fnfilter returns original row index and not current

fnGetSelected() after fnfilter returns original row index and not current

Starz26Starz26 Posts: 38Questions: 1Answers: 0
edited November 2011 in General
I have been reading all day yesterday trying to find the answer to this but.....

1. I need to get info from cells in the row a user clicks on.
2. The user has the ability to apply filters.

Scenario:

DT initializes with 5 rows of data.

fnFilter("Active|On-Hold",4,true,false,false ); is applied in the init block

Dt now shows - Showing 1 to 2 of 2 entries (filtered from 5 total entries)

When I click on the #2 visible row it returns the index of 4 (last row if all 5 were shown) which is the correct position without filtering. It should return the index of 1 (current position in filtered view.

I am using the row index value to get data from a hidden cell. since only row indexes 0, 1 are visible, passing the value of 4 causes an error as the DOM only has two rows visible.

Question: How to get the row index for the row clicked in DT based on the current view / state of the DT

Replies

  • Starz26Starz26 Posts: 38Questions: 1Answers: 0
    Additionally I have found that it does not work when sorting either....It still returns the original row index
  • Starz26Starz26 Posts: 38Questions: 1Answers: 0
    I think I solved this.....

    I used

    var indRow = j$(this).index();

    to get the index of the row clicked. Since I am using jQuery to get the index and not DT index, it returns the visible index...

    Then I could use that index to

    var anTds = tTable.fnGetTds( j$('[id$=fsaList] tbody tr:eq('+indRow+')')[0] );

    which returns the data for the visible row.....
  • allanallan Posts: 64,596Questions: 1Answers: 10,683 Site admin
    If you just want the data from a clicked row, then:

    [code]
    $('#example tbody tr').click( function () {
    var data = oTable.fnGetData( this );
    // do something with data
    } );
    [/code]

    would do it. There are a lot of small modifications you can make to this such as fnGetTds as you have above, but that's the basic idea.

    Allan
This discussion has been closed.