Get row

Get row

lockedscopelockedscope Posts: 8Questions: 1Answers: 0

How to access any row from a list of rows returned by dt.rows(".is-something")? Why does not dt.rows(".is-something")[0] work?

Replies

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769

    The rows() returns a Datatables API instance not the specific data. To get the data you would use rows().data(). The rows().data() example shown shows how to get the first row returned. So you could use something like this:
    dt.rows(".is-something").data()[0]

    Kevin

  • lockedscopelockedscope Posts: 8Questions: 1Answers: 0

    That's fine but what if we need to access to the html node(tr) for the row?

  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin

    Then use the row().node() method :).

    The API reference is available here.

    Allan

  • lockedscopelockedscope Posts: 8Questions: 1Answers: 0
    edited June 2017

    So, it is not simply possible after getting rows with dt.rows(".is-something") and select the first or nth. row and get its node()?

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769

    Maybe I'm missing something in your question but you could do something like this:

    var data = dt.rows(".is-something").nodes();
    console.log(data[0]);
    

    The rows() documentation states that it returns an API instance. Then you can use nodes() or data() or other API methods to get the desired data.

    Kevin

  • lockedscopelockedscope Posts: 8Questions: 1Answers: 0
    edited June 2017

    So, following is my solution.

      var rows = myTable.rows(":odd").eq(0).filter( function ( value, index ) {
      
            return (index == 1 || index == 2);
        } );
    
      console.dir(myTable.rows(rows));
      console.dir(myTable.rows(rows).nodes());
    
    // Following does not work
      console.dir(rows.nodes());
    
This discussion has been closed.