2017-12-18 185 views
0

如何在多个字段上创建过滤器,哪些过滤器在服务器上过滤,而不在本地存储中过滤?如何在多个字段上创建远程过滤器?分机Js 5

到目前为止,我只得到本地。

onFilter: function(field, newValue, oldValue, options){ 
    var grid = Ext.getCmp('grid'); 
    grid.store.clearFilter(); 

    if (newValue) { 
     var matcher = new RegExp(Ext.String.escapeRegex(newValue), "i"); 
     grid.store.filter({ 
      filterFn: function(record) { 
       return matcher.test(record.get('id')) || 
        matcher.test(record.get('names')); 
      } 
     }); 
    } 
} 

回答

1

您无法在远程过滤中使用filterFn设置过滤器。远程过滤只能采用发送到后端的属性值 - 运算符组合,并且必须由后端进行评估和处理。

要过滤的多个属性,你当然可以发送多个过滤器后端:然后

store.addFilters([{ 
    id: 'idFilter', 
    property: 'id', 
    operator: 'eq', 
    value: newValue 
},{ 
    id: 'nameFilter', 
    property: 'names', 
    operator: 'like', 
    value: newValue 
}]); 

后端有评估和这些过滤器适用于数据。这些值发送给后端无客户端验证或使用,所以你甚至可以发送任意的财产或经营者名称到后端:

store.addFilters([{ 
    id: 'idOrNameFilter', 
    property: 'idOrName', 
    operator: 'somethingsomething', 
    value: newValue 
}]); 

你只需要告诉你的后端正确解析属性名从参数字符串中并相应地执行。