【问题标题】:Extjs Sencha UUID custom sortingExtjs Sencha UUID 自定义排序
【发布时间】:2022-09-26 16:17:47
【问题描述】:

我正在尝试对我的网格的列 UUID 进行自定义排序。我希望排序反映数据库的排序,例如按降序显示数据,如下所示:

select * from mytable order by uuid desc;

|    id    |                uuid              | 
|----------+----------------------------------+
| 10094875 |                                  | 
| 10093749 |                                  | 
| 10094905 |                                  |       
| 10094887 |                                  |                  
| 11268062 | fffffffffffffffffffff            |                 
| 11268010 | fffffffffffffffffffff            | 
| 11267357 | ffffffffffff                     | 
| 11267356 | fffff-fffff-ffff-ffff-ffff       | 
| 11267998 | eeda671280c7397c11347cb758e36b38 | 
| 10250739 | eeda671280c7397c11347cb758e36b38 |  

因此,按降序排列,它应该首先出现空格/空项目,然后出现在没有破折号的 UUID 之后,然后是带有破折号的 UUID。

目前这些是我在降序排序时的结果:

它接近我想要的,但正如您所见,空行显示在底部而不是顶部。这是我的代码:

Ext.define(\'Traccar.model.MyModel\', {
    extend: \'Ext.data.Model\',
    identifier: \'negative\',

    fields: [{
        ...
    }, {
    name: \'uuid\',
    type: \'string\',
    sortType: function (actualValue, replaceValue, arg1, arg2) {
          if (arg1 != null & arg2 != null) {
              if (actualValue === arg1 || actualValue === arg2) {
                  return replaceValue;
              } else
                  return actualValue;
          } else if (arg1 != null) {
              if (actualValue === arg1)
                  return replaceValue;
              else
                  return actualValue;
          } else
              return actualValue;
      }
}, ..
    }],   
});

有谁知道我该如何解决?

  • 您的 ExtJS 版本/工具包是什么(现代或经典)?
  • extjs 版本\'6.2.0\'
  • 我在documentation函数sortType的这4个参数中没有看到,只有一个参数。

标签: javascript sorting extjs uuid custom-sort


【解决方案1】:

模型中不需要定义sortType,只需要定义字段string的类型即可。在您的商店中,只需添加一个分拣机,例如:

Ext.define('Traccar.store.MyStore', {
    model: 'negative',
    proxy: {...},
    sorters: [
        {
            property: 'uuid',
            direction: 'ASC'
        }
    ]
}

网格应该按照您的预期显示结果。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多