【问题标题】:applyfilter during runtime seems to not properly filter data运行时应用过滤器似乎无法正确过滤数据
【发布时间】:2019-05-12 16:45:49
【问题描述】:

我正在使用 jqxgrid 并且需要实现过滤。我注意到它具有过滤功能,因此我正在研究如何利用预先存在的工具。供参考:https://www.jqwidgets.com/angular-components-documentation/documentation/jqxgrid/angular-grid-filtering.htm?search=

所以我实现了一个带有触发事件的按钮的输入框:filterClick() 并正确获取正确的数据来创建和应用过滤器:

Info: isFilterSet 是一个布尔值,分配给 jqxGrid 的可过滤字段。 grid 是对 jqxgrid 的引用 filterText 是对输入框的引用

filterClicked(): void {
  let filtergroup = new jqx.filter();
  let filter_or_operator = "or";
  let filterCondition = "contains";
  let filterValue = this.filterText.nativeElement.value;  //confirmed.
  let f = filter.createfilter("stringfilter", filterValue, filterCondition);

  for (let col in this.datafields){
     // confirmed col.name == columnname
     this.grid.addfilter(col.name, filter);
  }

  this.isFilterSet = true;
  this.grid.applyfilters();
}

我注销了信息,但网格本身似乎没有更新。

我做错了什么吗?网格本身没有更新,但我一直在跟随,没有看到任何跳出来的东西。我还尝试将过滤器组的实例化移动到数组内部,以防它可能不喜欢共享对象。

我没有错误

【问题讨论】:

    标签: angular typescript jqxgrid jqxwidgets


    【解决方案1】:

    由于我没有让这个工作,我通过保留数据的副本来自己处理过滤,但使用会触发 onchange 的新数组更新数据适配器。

    setDataAdapter () : void {
        // this.data is the base array object containing all info
        let filterValue : string = "";
        if (this.filterText) filterValue = this.filterText.nativeElement.value;
        let reg = RegExp(filterValue, "ig");
    
        let src: any =
        {
          // if the input is empty, then it would just use data, otherwise it would filter.   My filter is only filtering strings, is case inspecific and tests the entire string.
          localdata: filterValue == "" ? this.data : this.data.filter( row => {
            for ( let key of Object.keys(row)){
              let content = row[key];
              if (typeof content === "string" && reg.test(content)){
                return true;
              }
            }
            return false;
          }),
          datatype: 'array',
          datafields: this.dataFields
        };
    
        this.grid.clearselection();
        this.dataAdapter = new jqx.dataAdapter(src);
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-12
      • 1970-01-01
      • 1970-01-01
      • 2019-05-31
      • 1970-01-01
      相关资源
      最近更新 更多