2011-09-08 35 views
2

我想實現我的播放應用JQuery的數據表。

這裏是我的代碼

#{extends 'main.html' /} 
    #{set title:'Customers List' /} 
    <link rel="stylesheet" media="screen" href="@{'/public/stylesheets/demo_table.css'}"> 
    <link rel="stylesheet" media="screen" href="@{'/public/stylesheets/demo_page.css'}"> 
    #{set 'moreScripts'} 
    <script src="@{'/public/javascripts/jquery-1.5.2.min.js'}" type="text/javascript" charset="${_response_encoding}"></script> 
    <script src="@{'/public/javascripts/jquery.dataTables.js'}" type="text/javascript" charset="${_response_encoding}"></script> 
    <script src="@{'/public/javascripts/jquery.js'}" type="text/javascript" charset="${_response_encoding}"></script> 
    <script> 
     $(document).ready(function() { 
      oTable = $('#example').dataTable(); 
     }); 
    </script> 
    #{/set} 
    <div class="others" align="center"> 
        <table width="100%" cellpadding="0" cellspacing="0" border="0" class="display" id="example"> 
         <thead> 
         <tr> 
           <th>Header1</th> 
           <th>Header2</th> 
         </tr> 
         </thead> 
         <tbody> 
          <tr> 
           <td>Col1</td> 
           <td>Col2</td> 
          </tr> 
         </tbody> 
        </table> 
    </div> 

當我運行JavaScript拋出一個錯誤

$("#example").dataTable is not a function 

我檢查了所有的JavaScript/CSS文件的頁面。所有文件都包含在內。 什麼可能是錯誤。

+0

難道您的應用通過在http://datatables.net/usage/所有要求? – toopay

回答

12

您必須在您的腳本部分加載數據表AFTER jQuery,並且只能包含jQuery一次。

嘗試刪除的jQuery第二(非精縮)的要求,看你怎麼走。

+0

謝謝你這麼多,我刪除了非精縮jQuery的,則數據表中被渲染,但不應用CSS – Arasu

+0

是它工作正常。 – Arasu

+0

很高興聽到你有它。 DataTables非常棒。 – RET

2

只有兩個原因錯誤

  1. 您還沒有包含數據表插件
  2. 您已經包括超過一次的jQuery插件

    ,如果你仍然有問題之前,jQuery插件比嘗試從cdn使用jquery插件 鏈接是http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js 並刪除所有其他jquery插件

+0

嘿。我使用同樣的事情播放框架,但它彈出一個錯誤: 數據表警告:表ID =數據表請求的未知參數「0」的第1行,我不知道這是什麼!? –