删除数据表搜索字段而不禁用可搜索的

时间:2018-06-06 10:22:09

标签: datatables angular5 angular-datatables

我使用angular-datatables在Angular5中创建了一个数据表。然后,我创建了表格页脚并实现了输入字段以单独搜索每个列,并将style="display: table-header-group;"添加到页脚,使其位于标题上方。

现在我想删除标准数据表搜索输入字段。 如果我只是在数据表配置中禁用它,那么自定义搜索字段将不起作用。 我还尝试将类dataTables_filter的值更改为display: none,但它不起作用,因为它从node_modules文件夹中获取样式。

我可以更改我的node_modules / datatables / style.css,但问题是,这是gitignore列表中唯一的文件夹,而不是我们的存储库。

这是我的代码: HTML:

<tfoot style="display: table-header-group;">
    <tr>
      <th style="width: 25%">

      </th>
      <th style="width: 25%">

      </th>
      <th style="width: 25%">
        <input type="text" placeholder="Search actions" name="search-actions" class="form-control" />
      </th>
      <th style="width: 25%">
        <input type="text" placeholder="Search messages" name="search-messages" class="form-control" />
      </th>
    </tr>        
  </tfoot>

打字稿:

ngOnInit(): void {
    this.dtOptions = {
      ajax: 'http://www.mocky.io/v2/5b0eb2083200006300c19bd8',
      columns: [{
        title: 'Date',
        data: 'date'
      }, {
        title: 'Time',
        data: 'time'
      }, {
        title: 'Action',
        data: 'action'
      }, {
        title: 'Message',
        data: 'message'
      }]
    };
  }

  ngAfterViewInit(): void {
    this.datatableElement.dtInstance.then((dtInstance: DataTables.Api) => {
      dtInstance.columns().every(function () {
        const that = this;
        $('input', this.footer()).on('keyup change', function () {
          if (that.search() !== this['value']) {
            that
              .search(this['value'])
              .draw();
          }
        });
      });
    });
  }

1 个答案:

答案 0 :(得分:2)

使用dom选项并从默认值(默认样式为{{1}})中排除{{1}}以隐藏过滤控件。

例如:

{{1}}