fnFindCellRowNodes

Search for data, returning row nodes

Much like fnFindCellRowIndexes this plug-in will search a table for matching data (optionally the search can be restricted to a single column), but in this case the returned array contains tr nodes of the matching rows, rather than data indexes.

Plug-in code

jQuery.fn.dataTableExt.oApi.fnFindCellRowNodes = function ( oSettings, sSearch, iColumn )
{
    var
        i,iLen, j, jLen, val,
        aOut = [], aData,
        columns = oSettings.aoColumns;

    for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
    {
        aData = oSettings.aoData[i]._aData;

        if ( iColumn === undefined )
        {
            for ( j=0, jLen=columns.length ; j<jLen ; j++ )
            {
                val = this.fnGetData(i, j);

                if ( val == sSearch )
                {
                    aOut.push( oSettings.aoData[i].nTr );
                }
            }
        }
        else if (this.fnGetData(i, iColumn) == sSearch )
        {
            aOut.push( oSettings.aoData[i].nTr );
        }
    }

    return aOut;
};

CDN

This plug-in is available on the DataTables CDN:

JS

Note that if you are using multiple plug-ins, it is beneficial in terms of performance to combine the plug-ins into a single file and host it on your own server, rather than making multiple requests to the DataTables CDN.

Version control

If you have any ideas for how this plug-in can be improved, or spot anything that is in error, it is available on GitHub and pull requests are very welcome!

Example

$(document).ready(function() {
      var table = $('#example').dataTable();

      var a = table.fnFindCellRowNodes( '1.7' );    // Search all columns

      var b = table.fnFindCellRowNodes( '1.7', 3 ); // Search only column 3
  } );