js-grid过滤器不呈现

时间:2019-01-15 18:42:34

标签: javascript filter jsgrid

我想在jsGrid中使用客户端过滤,并已在演示页(db.js文件)中实现了same controller as in hidden code,但是我遇到了一个问题:即使在以下情况下,过滤器行也不会显示:我添加了一个控制字段(不需要)以对其进行切换。

我的jsGrid初始化代码:

  function initGrid() {
    dom_accountList.jsGrid( {
        height: 500,
        width: '100%',

        autoload: true,
        filtering: false,
        editing: false,
        sorting: true,
        paging: true,

        pageSize: 25,
        pageButtonCount: 5,

        fields: accountList.layout,
        controller: accountList,

        data: accountList.data,

        rowClick: function (arg) {//redacted}
    });

    dom_accountList.jsGrid("option", "filtering", true);
  }

您可能会尝试纠正以下方面:

  1. “如果拥有控制器,则不需要数据” -否,作者: 反复试验我发现在包含静态数据之前不会调用loadData
  2. “但是过滤设置为FALSE!” -我知道。无论是定义为真,定义为缺失还是定义为假,然后在渲染后切换(如图所示),这些字段都不会在屏幕上渲染。

现在,我确实看到了HTML,但是全部为空:

<tr class="jsgrid-filter-row" style="display: table-row;">
    <td class="jsgrid-cell" style="width: 10px;"></td>
    <td class="jsgrid-cell" style="width: 65px;"></td>
    <td class="jsgrid-cell" style="width: 10px;"></td>
    <td class="jsgrid-cell" style="width: 10px;"></td>
</tr>

TD内应没有input标签吗? 为什么他们不见了?我想这就是症结所在。

如果有问题,这是从演示的db.js中修改的控制器代码:

  function loadData(filter) {

   return $.grep(this.data, function (item) {
     return (!filter.Account || item.Account.indexOf(filter.Account) > -1)
     && (!filter.AXfer || item.AXfer === filter.AXfer)
     && (!filter.BXfer || item.BXfer === filter.BXfer)
     && (!filter.Name || item.Name.indexOf(filter.Name) > -1)
   });
  };
  function insertItem() {};
  function updateItem() {};
  function deleteItem() {};

这是accountList.layout中的字段列表:

   accountList.layout = [
     {
       name: 'Account',
       title: 'Account',
       width: '10',
     },
     {
       name: 'Name',
       title: 'Name',
       width: '65',
     },
     {
       name: 'AXfer',
       title: 'ATeam',
       width: '10',
     },
     {
       name: 'BXfer',
       title: 'BGood',
       width: '10',
   ];
 }

1 个答案:

答案 0 :(得分:0)

哦,天哪,这就是答案:必须在字段定义中包含type属性:

  {
    name: 'Account',
    title: 'Account',
    width: '10',
    type: 'text',
  },
  {
    name: 'Name',
    title: 'Name',
    width: '65',
    type: 'text',
  },
  {
    name: 'AXfer',
    title: 'ATeam',
    width: '10',
    type: 'text',
  },
  {
    name: 'BXfer',
    title: 'BGood',
    width: '10',
    type: 'text',
  }