繁体   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