2016-07-16 6 views
2

データテーブル1.10に追加された新しい行を強調表示するのに失敗しました。ここでデータテーブルajaxソースデータの新しい行を強調表示

は、私のテーブルの初期化です:

$('#userList').DataTable({    
     serverSide: true, 
    serverMethod: "GET", 
    ajaxSource: base + "admin/users/users_list/showusers",  
     order: [ 0, "desc" ],  
     aoColumns: [ 
      {bVisible:false},         
      {data: null, 
      render: function (data, type, row){ 
      if(row[2] === '4'){ 
       return '<span class="text-lt">'+row[1]+'</span>'; 
      } else { 
       return row[1]; 
      } 
      } 
      }, 
      {data: null, 
      render: function (data, type, row){ 
      if(row[2] === '1'){ 
       return '<span class="label label-black">'+selectUG1+'</span>'; 
      } 
      else if(row[2] === '2') { 
       return '<span class="label label-primary">'+selectUG2+'</span>' 
      } 
      else if(row[2] === '3') { 
       return '<span class="label label-success">'+selectUG3+'</span>' 
      } 
      else if(row[2] === '4') { 
       return '<span class="label label-danger">'+selectUG4+'</span>' 
      } 
      } 
      }, 
      null, 
      {data:4, 
      render: function(data, type, row){ 
       return (moment(data).format("DD/MM/YYYY")); 
      } 
      }, 
      {data:5, 
      render: function(data, type, row){ 
       return (moment(data).format(tableDateTimeFormat)); 
      } 
      }, 
      {bSortable: false, className: 'all', 
      data: 6, 
      render: function(data, type, full, meta){ 
       return '<a href="'+base+'admin/users/edit_user/userid/'+data+'" class="animsition-link table-icon" data-toggle="tooltip" data-original-title="'+tooltipEdit+'">\ 
         <span class="fa-stack">\ 
         <i class="fa fa-square fa-stack-2x"></i>\ 
         <i class="fa fa-edit fa-stack-1x fa-inverse"></i>\ 
         </span>\ 
         </a>\ 
         <a href="#" id="'+data+'" class="table-icon red-icon delete" data-toggle="tooltip" data-original-title="'+tooltipDelete+'">\ 
         <span class="fa-stack">\ 
         <i class="fa fa-square fa-stack-2x"></i>\ 
         <i class="fa fa-trash fa-stack-1x fa-inverse"></i>\ 
         </span>\ 
         </a>';} 
      } 
     ]    
    }); 

サーバーによって返されたデータは、この形式の下にある:

setTimeout(function(){ 
     $.ajax({ 
      url: $form.attr('action'), 
      type: 'POST', 
      data: $form.serialize(), 
      success:function(response){ 
       if(response.success){      
        usertable.rows.add([       
        ]).draw().nodes().to$().addClass('animated fadeIn').effect('highlight',{},3000); 
        toastr.success(userAddSuccess) 
       }      
       $form.parents('.bootbox').modal('hide');    
      } 
     }); 
    }, 3000);   

["240", "fancy", "3", "[email protected]", "2016-07-16", "2016-07-16 14:09:23", "240"] 

私は次のメソッドを使用しています行は望みの効果なしで追加されますが、どこが間違っていますか?

+0

行は 'animated fadeIn'クラスを取得しますか? – billynoah

+0

いいえ、これもハイライト効果はありません。 – blips

答えて

0

serverSide: trueで有効になっているサーバー側の処理があるため、新しい行がハイライトされていないと考えられます。このモードでは、draw() APIメソッドを呼び出すと、サーバーへのリクエストがトリガーされます。プラグインは追加された行を知らないので、nodes()の呼び出しは0要素を返します。

+0

ご返信ありがとうございます。 DT_RowIdプロパティを持つ各行にidを追加しようとすると、serverSideの問題を解決できると思いますか? – blips

+0

@blips、そ​​れを修正するいくつかの方法があります。 'response'変数の値が何であるかははっきりしておらず、' rows.add([]) '呼び出しにはデータがないので、より詳細な答えは得られませんでした。新しく追加された行のIDを知っていれば(例では '240'です)、テーブルページ[' draw'](https://datatables.net/reference/event/draw)イベントでそれを見つけることができます['fnFindCellRowIndexes()'](https://datatables.net/plug-ins/api/fnFindCellRowIndexes)プラグイン)を選択し、強調表示します。 –

+0

あなたの提案をありがとう、今私は何をすべきか知っています。 – blips

関連する問題