2012-05-30 2 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 프로그래밍을 처음 사용합니다. 브라우저에서 테이블을 비교할 때 오류가 표시됩니다.데이터 테이블이있는 특정 열 필터

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는 동일한 테이블입니다. 오류는 기본적으로이 테이블을 한 번 초기화 했으므로 다시 할 수 없다는 의미입니다.

첫 번째 코드 블록을 제거하면 문제가 해결됩니다.