duanbei7035 2016-04-13 07:57
浏览 65
已采纳

我们如何在jQuery Datatable调用结果中启动另一个jQuery插件而不是页面就绪函数?

For my web application, iam using jQuery datatable with ajax to fetch data from database.Actually 'icheck' is initiated in jQuery page ready function.What the problem is after calling datatable or any filter or search happens in datatable, getting data correctly and icheck check boxes are showing as normal check boxes. How can i recall the icheck plugin call inside datatable call.My Code is as follows

<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 is as follows

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

Please help me to fix it..

  • 写回答

1条回答 默认 最新

  • du4822 2016-04-20 05:28
    关注

    Oh..Finally i found it..This may help others..One api function instead of ajax success is already there inside datatable plugin..That is "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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥200 csgo2的viewmatrix值是否还有别的获取方式
  • ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊
  • ¥15 请把下列每一行代码完整地读懂并注释出来
  • ¥15 pycharm运行main文件,显示没有conda环境
  • ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件
  • ¥15 为什么eclipse不能再下载了?
  • ¥15 编辑cmake lists 明明写了project项目名,但是还是报错怎么回事
  • ¥15 关于#计算机视觉#的问题:求一份高质量桥梁多病害数据集
  • ¥15 特定网页无法访问,已排除网页问题
  • ¥50 如何将脑的图像投影到颅骨上