2016-09-15 9 views
0

私は、データテーブルServer Sideを使用して、私のウェブサイト上にページテーブル付きのMySQLテーブルを生成しています。DataTablesのcolumns.renderオプションが複数の列で機能しなくなるのはなぜですか?

私はそうのようなMySQLの列のいずれかにハイパーリンクを追加するにはrenderオプションを使用しています:

 $(document).ready(function() { 
      $('#example').DataTable({ 
       "processing": true, 
       "serverSide": true, 
       "ajax": "includes/pull_2.php", 
       "columns": [ 
        { 
         "render": function (data, type, full, meta) { 
          return "<a href=" + full[0] + ">" + full[0] +"</a>"; } 
        } 
       ] 
      }); 
     }); 

私は私のテーブル内の1つの列を持っている場合、これは完璧に動作します。たとえば:

<table id="example" class="display" cellspacing="0" width="100%"> 
     <thead> 
      <tr> 
       <th>First Name</th> 
      </tr> 
     </thead> 
     <tfoot> 
      <tr> 
       <th>First Name</th> 
      </tr> 
     </tfoot> 
    </table> 

しかし、できるだけ早く私は、テーブルに配列し、別の<th>に別の列を追加すると、テーブルには、すべてのテーブルをレンダリングし、単に「処理」とは言い停止します。 http://clients.serallo.co.uk/formtest/

誰が予想通り、これは動作しない理由として提案を持っています:

これは、私が働いているテーブルのですか?

答えて

0

columnsの要素の数は、表の列の数と一致する必要があります。

代わりにcolumnDefsオプションを使用して、特定の列をターゲットにすることができます。例:

$('#example').DataTable({ 
    "processing": true, 
    "serverSide": true, 
    "ajax": "includes/pull_2.php", 
    "columnsDefs": [ 
     { 
     "targets": 0, 
     "render": function (data, type, full, meta) { 
      return "<a href=" + full[0] + ">" + full[0] +"</a>"; 
     } 
     } 
    ] 
}); 
関連する問題