簡體   English   中英

我們如何在jQuery Datatable調用結果內部而不是頁面就緒函數中啟動另一個jQuery插件?

[英]How can we initiate another jQuery plugin inside jQuery Datatable call results instead of page ready function?

對於我的Web應用程序,iam使用帶有ajax的jQuery數據表從數據庫中獲取數據。實際上是在jQuery頁面就緒函數中啟動了'icheck'。調用數據表或在數據表中進行任何過濾或搜索后,問題出在什么地方,正確獲取數據並進行icheck復選框顯示為普通復選框。 我該如何在數據表調用中調用icheck插件調用。我的代碼如下

<table id="viewcat" class="table table-bordered table-striped mar-bottom0 mydatatable">
  <thead>
    <tr>
      <th style="width: 9%"><input type="checkbox" class="minimal" id="bulkDelete" /> <button type="submit" id="deleteTriger" name="submit" class="btn btn-primary btn-xs hor-align" value="Delete Selected" >Delete</button></th>
      <th style="width: 2%">Sl.no</th>
      <th style="width: 15%">Category Name</th>                  
      <th style="width: 20%">Reference Links</th>
      <th style="width: 25%">Image</th>
      <th style="width: 15%"></th>
      <th style="width: 10%"></th>
    </tr>
  </thead>                  
</table>

腳本如下

<script>
  $(function (){    
    $("#viewcat").DataTable({
      "fnRowCallback" : function(nRow, aData, iDisplayIndex){               
               $("td:nth-child(2)", nRow).append(aData[7]);
               return nRow;
            },      
      "processing": true,
      "serverSide": true,
      "order": [ 2, "asc" ],
      "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 0, 1, 4, 5 ,6] } ],
      "ajax":{
          url :"maincategory/viewdata.php", // json datasource
          type: "post",        
          error: function(){  
          $(".viewcat-error").html("");
          $("#viewcat").append('<tbody class="viewcat-error"><tr><th colspan="7">No data found in the server</th></tr></tbody>');
          $("#viewcat_processing").css("display","none");          
          }
      }
    });

  });
</script>

請幫助我修復它。

哦..最后我找到了..這可能會對其他人有所幫助..datatable插件內部已經有一個api函數而不是ajax成功。.即“ fnDrawCallback”。

<script>
  $(function (){    
    $("#viewcat").DataTable({
      "fnRowCallback" : function(nRow, aData, iDisplayIndex){               
               $("td:nth-child(2)", nRow).append(aData[7]);
               return nRow;
            },
      "fnDrawCallback": function( oSettings ){
              $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
                  checkboxClass: 'icheckbox_minimal-blue',
                  radioClass: 'iradio_minimal-blue'
                });},      
      "processing": true,
      "serverSide": true,
      "order": [ 2, "asc" ],
      "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 0, 1, 4, 5 ,6] } ],
      "ajax":{
          url :"maincategory/viewdata.php", // json datasource
          type: "post",        
          error: function(){  
          $(".viewcat-error").html("");
          $("#viewcat").append('<tbody class="viewcat-error"><tr><th colspan="7">No data found in the server</th></tr></tbody>');
          $("#viewcat_processing").css("display","none");          
          }
      }
    });

  });
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM