0

我有用于日期和数字的格式化程序。由于某种原因,我的链接格式化程序只工作了一半。我在网格中得到的只是这样的链接:

?id=1

URL 中未使用(或包含)baseLinkUrl 设置的位置。

这是我的 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"
}
4

1 回答 1

1

返回服务器的数据不包含"id"属性。如果column 在您的网格中invid发挥作用,id您应该首先更改id: 'id'to和 seconds (通常它是一种替代方法,但我建议同时使用)以将属性添加到column 的定义中。jsonReaderid: 'invid'key: trueinvid

下一个重要问题:您使用formatteroptions而不是formatoptions. 因此,您使用的大多数设置现在将被忽略。

formatoptions还有一个问题:您对of使用了错误的值formatter: "date"您需要以 PHP 格式提供 jqGrid 数据,而不是此处描述的更常见的数据。如果您打开grid.locale-en.js(参见此处),您会发现一些使用日期示例和一些可能对您有所帮助的链接。

于 2013-04-29T17:17:24.833 回答