2014-01-23 64 views
0

我正在使用JTable(JQuery)顯示數據庫中的某些記錄(數據庫是MySQL) 我也使用JTable的createAction插入數據。我有3個字段在JTable中顯示日期。我面臨的問題是當顯示日期的字段添加Type:'date'時,jtable停止顯示來自數據庫的記錄。但是當我在字段中刪除類型:'data'時,它再次使用listAction開始顯示數據。我不明白爲什麼會發生這種情況? 我想要創建窗體來顯示日期選擇器,並且還希望日期顯示在listAction中。JTable JQuery不顯示記錄

注意:我使用yyyy-mm-dd格式作爲日期。以下代碼清單記錄來自數據庫時的類型:'date'已從中刪除dateApplied,startDate和endDate字段。但是在這些字段的代碼中輸入:'date'時,它將無法顯示記錄。

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 

<%@ page import="java.util.ArrayList"%> 
<%@ page import="daobject.*"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<link href="../css/metro/red/jtable.css" rel="stylesheet" type="text/css" /> 
<link href="../css/jquery-ui-1.10.3.custom.css" rel="stylesheet" type="text/css" /> 
<script src="../js/jquery-1.8.2.js" type="text/javascript"></script> 
<script src="../js/jquery-ui-1.10.3.custom.js" type="text/javascript"></script> 
<script src="../js/jquery.jtable.js" type="text/javascript"></script> 

<link rel="stylesheet" href="../css/jquery-ui.css" type="text/css"> 
<link rel="stylesheet" href="../css/calenderStyle.css" type="text/css"> 

<title>Leave Applications</title> 
<script type="text/javascript"> 
    $(document).ready(function() { 
     $('#StudentLeaveTableContainer').jtable({ 
      title: 'Leave Applications', 
      actions: { 
        listAction: '/Final_Notebook/StudentLeaveCancelController?action=list', 
        createAction: '/Final_Notebook/StudentLeaveCancelController?action=create', 
        deleteAction: '/Final_Notebook/StudentLeaveCancelController?action=delete'   
      }, 

      fields: { 
       To:{ 
        title:'Application To', 
        create: true, 
        options: '/Final_Notebook/StudentLeaveCancelController?options=ApplicationTo', 
        list: false 
        }, 

       leaveId:{ 
        key: true, 
        create: false, 
        edit: true,   
        sorting: false, 
        list: false 
       }, 
       name: { 
        title:'Name', 
        list: true, 
        create:false, 
       }, 
       rollNo: { 
        title: 'Roll No', 
        width: '20%', 
        list: true, 
        edit:true, 
        create: false 
       }, 
       leaveType: { 
        title: 'Type', 
        width: '20%', 
        options:{'personal':'personal','medical':'medical','other':'other'}, 
        edit:false, 
        create: true, 
        list: true 
       }, 
       leaveReason: { 
        title: 'Reason', 
        width: '30%', 
        type: 'textarea', 
        edit: false, 
        list: true, 
        create: true 
       }, 
       dateApplied: { 
        title: 'Applied On', 
        width: '30%', 
        list: true, 
        create: true, 
        edit: true, 
        type: 'date', 
        displayFormat: 'yy-mm-dd' 
       }, 
       startDate: { 
        title: 'From Date', 
        width: '30%', 
        list: true, 
        create: true, 
        edit: true, 
        type: 'date', 
        displayFormat: 'yy-mm-dd' 
       }, 
       endDate: { 
        title: 'To Date', 
        width: '30%', 
        list: true, 
        create: true, 
        edit: true, 
        type: 'date', 
        displayFormat: 'yy-mm-dd' 
       }, 
       days: { 
        title: 'Total Days', 
        width: '20%', 
        edit: false, 
        create: true, 
        list: true 
       }, 
       status: { 
        title: 'Status', 
        width: '20%', 
        list: true, 
        edit: false, 
        create: false, 
        options: {'0':'pending', '1':'Apprtoved', '2':'Rejected'} 
       } 
      } 
     }); 
     $('#StudentLeaveTableContainer').jtable('load'); 
    }); 
</script> 
</head> 

<body> 

<div style="width:70%;margin-right:20%;margin-left:20%;text-align:center;"> 
<h1>Leave Applications</h1> 
<div id="StudentLeaveTableContainer"></div> 
</div> 
</body> 
</html> 
+0

只是一個小頭,你不需要指定列表:true,則創建:真實編輯:真正的,因爲他們是默認爲true。 http://www.jtable.org/ApiReference/FieldOptions – JCharette

+0

另外,你可以告訴我們你的listAction JSON嗎? – JCharette

回答

0
to display records try following: 
    dateApplied: { 
       title: 'Applied On', 
       width: '30%', 
       list: true, 
       create: true, 
       edit: true, 
       type: 'date', 
       displayFormat: 'yy-mm-dd', 
       display: function (data) { 
         return data.record.<your-field-name>; 
        }, 
      },