jqGrid 工具栏在输入时不过滤

jqGrid toobar not filtering when typing

使用 jqGrid js v5.5.0,您键入时筛选功能对某些字段不起作用。

在“标题”字段中键入内容会导致该列仅显示与输入内容匹配的值。

在串行过滤器中输入“2”不会显示任何内容。

预期的结果是序列栏的行为与标题栏完全一致,并显示部分匹配项。

所有数据都预加载到网格中。

这是代码和 Fiddle 演示问题的代码。

http://jsfiddle.net/rboarman/p7uyq6w2/15/

var mydata = [{
    "Id": "5b1600409fc4a04a1001af6c",
    "HitNumber": "2169957",
    "Title": "Centrifuge",
    "ClientIdNumber": "",
    "Status": "Requested",
    "IsVisible": false,
    "Manufacturer": "Corning",
    "ModelNumber": "6765/C1501",
    "SerialNumber": "",
    "BookValue": "0",
    "Location": "San Francisco, CA",
    "ServiceStatus": "",
    "Condition": "",
    "Category": "Centrifuge",
    "Catalog": "Default",
    "Selected": "0",
    "AvailForRedeploy": "/Date(1485849600000)/"
  },
  {
    "Id": "5b1600409fc4a04a1001af6b",
    "HitNumber": "2169956",
    "Title": "Centrifuge",
    "ClientIdNumber": "",
    "Status": "Requested",
    "IsVisible": false,
    "Manufacturer": "Corning",
    "ModelNumber": "6765/C1501",
    "SerialNumber": "",
    "BookValue": "0",
    "Location": "San Francisco, CA",
    "ServiceStatus": "",
    "Condition": "",
    "Category": "Centrifuge",
    "Catalog": "Default",
    "Selected": "0",
    "AvailForRedeploy": "/Date(1485849600000)/",
  },
  {
    "Id": "5b1600409fc4a04a1001af70",
    "HitNumber": "2169961",
    "Title": "Pipettes",
    "ClientIdNumber": "",
    "Status": "Available",
    "IsVisible": true,
    "Manufacturer": "Sartorius",
    "ModelNumber": "Picus / Tacta",
    "SerialNumber": "",
    "BookValue": "0",
    "Location": "San Francisco, CA",
    "ServiceStatus": "",
    "Condition": "",
    "Category": "Pipettes",
    "Catalog": "Default",
    "Selected": "0",
    "AvailForRedeploy": "/Date(1485849600000)/",
  }
];

grid = $("#jqgrid").jqGrid({
  data: mydata, //insert data from the data object we created above
  datatype: 'local',
  ajaxGridOptions: {
    contentType: 'application/json; charset=utf-8'
  },
  height: 'auto',
  colNames: ['Id', 'Serial', 'Title', 'AvailForRedeploy'],
  colModel: [{
      name: 'Id',
      index: 'Id',
      hidden: true,
    },
    {
      name: 'HitNumber',
      index: 'Hit #',
      sortable: true,
      search: true
    },
    {
      name: 'Title',
      index: 'Title',
      sortable: true,
    },
    {
      name: 'AvailForRedeploy',
      index: 'AvailForRedeploy',
      formatter: 'date',
      formatoptions: {
        srcformat: "ISO8601Long",
        newformat: "m/d/Y h:i A"
      },
      sortable: true,
    }
  ],
  rowNum: 25,
  rowTotal: 2000,
  loadonce: true,
  rowList: [25, 50, 100],
  pager: '#pjqgrid',
  sortname: 'id',
  toolbarfilter: true,
  viewrecords: true,
  sortorder: "asc",
  caption: "",
  multiselect: true,
  multiboxonly: true,
  autowidth: true,
  toolbar: [true, "both"],
});

$("#jqgrid").filterToolbar({
  stringResult: true,
  searchOnEnter: false
});

您的问题出在 colModel 的定义中,尤其是索引 属性。

此 属性 不能与 space 一起使用。此外,索引 属性 在定义时用于搜索。你的定义是:

{
    name: 'HitNumber',
    index: 'Hit #',
    sortable: true,
    search: true
},

这是不正确的。为了使它起作用,请设置您的数据中使用的名称:即

{
    name: 'HitNumber',
    index: 'HitNumber,
    sortable: true,
    search: true
},

有关 colModel 选项的更多信息 index 您可以在我们的 documentation here

中阅读