2

私はデータテーブルを使用するのが初めてです。

要件は次のとおりです。テーブル(4列のテーブル)にカーソルを合わせたときに、セルの行番号と列番号を取得するには。各行の 2 列目にマウスを置くと、2 列目の値を説明するポップアップを表示する必要があります (4 列目には隠しておきました)。

私は周りを検索し、列番号を取得することに関する情報を得ましたが、行番号と列番号を同時に取得することはできませんでした。

私が使用したコードは以下の通りです:

jQuery(document).ready(function() {
    var oTable = $('#example').dataTable( {
        "bSortClasses": false
    } );

    $('td').hover( function( nRow, aData, iDisplayIndex ) {
        var iCol = $('td').index(this)%4 ;
        console.log(iCol);
        var iRow = $('tr').index(this) ;
        console.log(iRow);

        if(iCol=='1'){ // if 2nd col
        console.log(aData[3]);// this is the description i have to show- How to show this value 
        }
    }, function() {

    } );

}); 

上記のコードでは、col no を取得しますが、iRow は -1 を返し、aData[iCol] はエラーを として表示しUncaught TypeError: Cannot read property ’3′ of undefinedます。これは、aData 自体が定義されていないためです。では、4 番目の列の値を取得するには、何を使用する必要がありますか

私も次の方法を試してみました:

  1. tr--> $('tr').hover( function( nRow, aData, iDisplayIndex ) .... の代わりにホバーを変更するとtd、行は取得されませんが、iCol の列は -1 を返しません。
  2. テーブル #example --> $('#example').hover( function( nRow, aData, iDisplayIndex ) .... をチェックするようにホバーを変更すると、 iRow と iCol の両方で -1 を取得します

使ってみた

var data = oTable .fnGetData(this);
console.log(data);

データが私を返します

  1. $('td').hover の列の値 ...
  2. $('tr').hover の行の値....しかし、iCol 値を hv していないため、データ [iCol] を取得できません。
4

1 に答える 1