• ExtJs 7.X grid filter remote 自定义查询字段别名


    背景:ExtJs7.X系列,我们可以在gridPanel的column中配置filter属性进行远程数据过滤,可实现filedName=XXX,但是无法指定字段的别名,例如a.filedName=XXX,经过源码调试研究,已解决,具体见下文介绍,本文基于Ext7.6。

    1、修改ext-all.js源码

    目前我是基于ext-all-debug.js源码进行修改,然后进行最小化操作。

    修改的类为Ext.grid.filters.filter.SingleFilter,具体内容如下:

    1. Ext.define('Ext.grid.filters.filter.SingleFilter', {
    2. extend: 'Ext.grid.filters.filter.Base',
    3. constructor: function(config) {
    4. var me = this,
    5. filter, value;
    6. me.callParent([
    7. config
    8. ]);
    9. value = me.value;
    10. filter = me.getStoreFilter();
    11. if (filter) {
    12. // This filter was restored from stateful filters on the store so enforce it as active.
    13. me.active = true;
    14. } else {
    15. // Once we've reached this block, we know that this grid filter doesn't have a stateful
    16. // filter, so if our flag to begin saving future filter mutations is set we know
    17. // that any configured filter must be nulled out or it will replace our stateful filter.
    18. if (me.grid.stateful && me.getGridStore().saveStatefulFilters) {
    19. value = undefined;
    20. }
    21. // TODO: What do we mean by value === null ?
    22. me.active = me.getActiveState(config, value);
    23. // Now we're acting on user configs so let's not futz with any assumed settings.
    24. filter = me.createFilter({
    25. operator: me.operator,
    26. value: value,
    27. // 在源码中增加这个属性,可以在生成field=XXX的时候利用property指定别名
    28. property: me.property || false
    29. });
    30. if (me.active) {
    31. me.addStoreFilter(filter);
    32. }
    33. }
    34. if (me.active) {
    35. me.setColumnActive(true);
    36. }
    37. me.filter = filter;
    38. },
    39. activate: function(showingMenu) {
    40. if (showingMenu) {
    41. this.activateMenu();
    42. } else {
    43. this.addStoreFilter(this.filter);
    44. }
    45. },
    46. deactivate: function() {
    47. this.removeStoreFilter(this.filter);
    48. },
    49. getValue: function(field) {
    50. return field.getValue();
    51. },
    52. onFilterRemove: function() {
    53. // Filters can be removed at any time, even before a column filter's menu
    54. // has been created (i.e., store.clearFilter()).
    55. if (!this.menu || this.active) {
    56. this.active = false;
    57. }
    58. }
    59. });

            图1

    上文在createFilter的时候,同时拷贝property属性。

    2、源码分析

    见ext-debug-all.js中类Ext.grid.filters.filter.Base.getFilterConfig方法:

    1. // Note that some derived classes may need to do specific processing
    2. // and will have its own version of this method before calling parent (see the List filter).
    3. getFilterConfig: function(config, key) {
    4. config.id = this.getBaseIdPrefix();
    5. // 如果没有config.property属性,那么查询字段默认为column.dataIndex
    6. if (!config.property) {
    7. config.property = this.dataIndex;
    8. }
    9. if (!config.root) {
    10. config.root = this.defaultRoot;
    11. }
    12. if (key) {
    13. config.id += '-' + key;
    14. }
    15. config.serializer = this.getSerializer();
    16. return config;
    17. },

    图2

    如果没有config.property属性,那么查询字段默认为column.dataIndex。

    而经调试发现,图1中的filter对象即为图2中的config参数,而原来代码中filter中没有拷贝property对象,因此图2 !config.property 判断永远为false,因此ExtJs7.X 系列永远只能默认使用column.filed.dataIndex作为查询字段,即时配置了property属性也无效。

    3、效果演示

    3.1、定义Store的时候指定remoteFilter为true,使用远程过滤模式。

     3.2、配置grid.column的时候,指定过滤的filed增加property参数。

     3.3、查看实际请求

     3.4、后台调试条件信息

     经过后台参数解析处理,自动拼接转化为QueryWrapper对象,利用MybatisPlus进行条件过滤查询。

  • 相关阅读:
    ShaderLab实现序列帧动画
    springboot的配置文件
    DevEco Studio 3.0编辑器配置技巧篇
    Springframework之ResponseBodyAdvice——响应拦截处理
    asp.net core mvc 路由
    面试题(真题)
    【PG】PostgreSQL查看与修改参数
    工厂方法模式 创建型模式之四
    SwiftUI CoreData 教程之如何加速搜索速度
    java推送数据到指定的外部接口
  • 原文地址:https://blog.csdn.net/sword_happy/article/details/126872164