2012-05-30 143 views
0
<script type="text/javascript" charset="utf-8"> 
//initialisation code 
    $(document).ready(function() { 
     $('#example').dataTable({ 
      "sPaginationType": "full_numbers", 



     }); 
    }); 

    var asInitVals = new Array(); 

    $(document).ready(function() { 

     $("tfoot input").each(function (i) { 
      asInitVals[i] = this.value; 
     }); 


     $("tfoot input").focus(function() { 
      if (this.className == "search_init") 
      { 
       this.className = ""; 
       this.value = ""; 
      } 
     }); 
     $("tfoot input").blur(function (i) { 
      if (this.value == "") 
      { 
       this.className = "search_init"; 
       this.value = asInitVals[$("tfoot input").index(this)]; 
      } 
     }); 

     var oTable = $('.exam').dataTable({ 
      "oLanguage": { 
       "sSearch": "Search all columns:" 
      }, 
      "bStateSave": true, 
      "fnInitComplete": function() { 
       var oSettings = $('.exam').dataTable().fnSettings(); 
       for (var i=0 ; i<oSettings.aoPreSearchCols.length ; i++){ 
        if(oSettings.aoPreSearchCols[i].sSearch.length>0){ 
         $("tfoot input")[i].value = oSettings.aoPreSearchCols[i].sSearch; 
         $("tfoot input")[i].className = ""; 
        } 
       } 
      } 
     }); 

     $("tfoot input").keyup(function() { 
      /* Filter on the column (the index) of this element */ 
      oTable.fnFilter(this.value, $("tfoot input").index(this)); 
     }); 

    }); 
</script> 

</head> 

<body> 

<table id="example" class = "exam" width="100%" border="1" cellpadding="0" cellspacing="0" class="pretty" align="center"> 

我是新來的jQuery編程。當我viwew在瀏覽器中的表我看到錯誤:特定的列過濾器

Data Tables warning (table id = 'example'): can not reinitialise Data Table. To retrieve the data table object for this table, pass no arguments or see the docs for bRetrieve and bDestroy

如何解決這個問題?

回答

0

您試圖初始化同一個表兩次。首先,您正在運行

$(document).ready(function() { 
    $('#example').dataTable({ 
     "sPaginationType": "full_numbers", 



    }); 
}); 

哪個嘗試使用示例的ID來初始化表上的數據表。然後嘗試再次在這裏初始化:

var oTable = $('.exam').dataTable({ 
     "oLanguage": { 
      "sSearch": "Search all columns:" 
     }, 
     "bStateSave": true, 
     "fnInitComplete": function() { 
      var oSettings = $('.exam').dataTable().fnSettings(); 
      for (var i=0 ; i<oSettings.aoPreSearchCols.length ; i++){ 
       if(oSettings.aoPreSearchCols[i].sSearch.length>0){ 
        $("tfoot input")[i].value = oSettings.aoPreSearchCols[i].sSearch; 
        $("tfoot input")[i].className = ""; 
       } 
      } 
     } 
    }); 

這裏要初始化表類考試。在這種情況下,具有班級考試的表格和示例的ID是相同的表格。錯誤基本上是說,嘿,我已經初始化了這張桌子一次,我不能再做一次。

刪除第一塊代碼,它應該可以解決您的問題。