2013-04-29 61 views
0

我有格式化工作日期和數字。由於某種原因,我的鏈接格式化程序僅中途中斷。所有我在電網得到的是這樣的鏈接:如果不被使用的baseLinkUrl設置(或包含)在URLjqgrid showLink不工作

?id=1 

這裏是我的JavaScript:

$(function() { 
    $("#d5d02a55-ba5e-46f2-a64a-05fd7870b273_list") 
     .jqGrid({ 
     url: '/jqgrid2/getDataJson', 
     datatype: 'json', 
     mtype: 'GET', 
     colNames: ['Inv No', 'Date', 'Amount', 'Tax', 'Total', 'Notes'], 
     colModel: [{ 
       "name": "invid", 
       "index": "invid", 
       "width": 55, 
       "formatter": "showlink", 
       "formatteroptions": { 
        "baseLinkUrl": "jsp/samplePage.jsp", 
        "target": "_blank", 
        "idName": "invid" 
       } 
      }, { 
       "name": "invdate", 
       "index": "invdate", 
       "width": 90, 
       "formatter": "date", 
       "formatteroptions": { 
        "srcformat": "yyyy-MM-dd", 
        "newformat": "MM/dd/yyyy" 
       } 
      }, { 
       "name": "amount", 
       "index": "amount", 
       "width": 80, 
       "align": "RIGHT", 
       "formatter": "number", 
       "formatteroptions": { 
        "decimalPlaces": 2 
       } 
      }, { 
       "name": "tax", 
       "index": "tax", 
       "width": 80, 
       "align": "RIGHT", 
       "formatter": "number", 
       "formatteroptions": { 
        "decimalPlaces": 2 
       } 
      }, { 
       "name": "total", 
       "index": "total", 
       "width": 80, 
       "align": "RIGHT", 
       "formatter": "number", 
       "formatteroptions": { 
        "decimalPlaces": 2 
       } 
      }, { 
       "name": "note", 
       "index": "note", 
       "width": 150, 
       "sortable": false 
      } 
     ], 
     pager: '#d5d02a55-ba5e-46f2-a64a-05fd7870b273_pager', 
     rowNum: 5, 
     rowList: [5, 10, 25, 50], 
     sortname: 'invid', 
     sortorder: 'asc', 
     viewrecords: true, 
     multiselect: false, 
     gridview: true, 
     caption: '', 
     height: 'auto', 
     jsonReader: { 
      root: 'data', 
      page: 'currentPage', 
      total: 'totalPages', 
      records: 'totalRecords', 
      repeatitems: false, 
      id: 'id' 
     } 
    }); 
}); 

而且我的數據:

{ "currentPage" : "1", 
    "data" : [ { "amount" : 1000.0, 
     "invdate" : "2013-04-01 00:00:00", 
     "invid" : 1, 
     "note" : "No notes", 
     "tax" : 60.0, 
     "total" : 1060.0 
     }, 
     { "amount" : 200.0, 
     "invdate" : "2013-04-02 00:00:00", 
     "invid" : 2, 
     "note" : "", 
     "tax" : 12.0, 
     "total" : 212.0 
     }, 
     { "amount" : 500.0, 
     "invdate" : "2013-04-03 00:00:00", 
     "invid" : 3, 
     "note" : "", 
     "tax" : 30.0, 
     "total" : 530.0 
     }, 
     { "amount" : 400.0, 
     "invdate" : "2013-04-03 00:00:00", 
     "invid" : 4, 
     "note" : "Some notes", 
     "tax" : 24.0, 
     "total" : 424.0 
     }, 
     { "amount" : 200.0, 
     "invdate" : "2013-04-04 00:00:00", 
     "invid" : 5, 
     "note" : "", 
     "tax" : 12.0, 
     "total" : 2012.0 
     } 
    ], 
    "limitRows" : "5", 
    "totalPages" : "3", 
    "totalRows" : "11" 
} 

回答

1

返回服務器不包含"id"屬性的數據。如果invid列在網格發揮id的角色,你首先應該在jsonReader改變id: 'id'id: 'invid'和秒(一般這是一種選擇,但我建議同時使用)來key: true屬性添加到invid列的定義。

下一個重要問題:您使用formatteroptions而不是formatoptions。所以你使用的大部分設置現在都會被忽略。

還有一個問題:對formatoptionsformatter: "date"使用了錯誤的值。您需要以PHP格式提供jqGrid數據,而不是像here所描述的更常用的數據。如果您打開grid.locale-en.js(請參閱here),您會發現一些使用日期的示例和一些可能對您有用的鏈接。

+0

我更正了格式選項拼寫錯誤,更改了日期格式,並且所有格式都顯示正在工作。大!我沒有對id做jsonReader的更改,並且URL呈現正常。我不知道這是爲什麼? – 2013-04-29 18:18:02

+0

@MichaelSobczak:你是否包含'key:true'屬性?你確認你在第二頁上有正確的ID嗎?如果在網格中沒有找到id,那麼默認情況下將使用值1,2,3 ......(比如來自第一頁的id)。 – Oleg 2013-04-29 19:23:24

+0

我的示例數據的ID爲1,2,3,所以我的測試無效。讓我嘗試添加「key」屬性,並添加一行ID,該行在當前表中最後一個之後的幾個項目中,以確保事情工作正常。謝謝你的提示! – 2013-04-29 21:46:02