【问题标题】:What comparator does Vuetify use to sort data table String columnsVuetify 使用什么比较器对数据表 String 列进行排序
【发布时间】:2020-09-13 07:28:21
【问题描述】:

如果我采用标准的 Vuetify 示例并将卡路里更改为包含字符串,那么现在数据并非都是数字: https://codepen.io/hobbeschild/pen/WNQWmrJ

那么 Vuetify 在内部使用什么比较器来订购这些字符串?

假设我有另一个带有 v-select 的页面,我想为用户提供表格中其他页面上的所有卡路里选项,并且我想以与它们相同的顺序显示卡路里按升序排序时的表格。我怎样才能复制它?

我认为在填充 v-select 之前我需要做这样的事情(这不会对它们进行完全正确的排序,但我认为它会是类似的):

calories.sort((a, b) => a.localeCompare(b, undefined, { numeric: true, sensitivity: 'base' }))

我想象 v-data-table 代码在内部执行 localeCompare 或类似的操作,我只需要它使用的参数。

【问题讨论】:

  • 你可能想看看名为custom-sort的道具。
  • @YomS。我不想在桌子上放置自定义排序。桌子很好。它可以保持原样。我想知道它在默认排序的幕后做了什么。它使用什么比较器?

标签: sorting vue.js ecmascript-6 vuetify.js v-data-table


【解决方案1】:

我觉得可能是这样

https://github.com/vuetifyjs/vuetify/blob/268434aa851dded8b67c0e67bfa39b3cbe791584/packages/vuetify/src/util/helpers.ts#L285

虽然我不确定如何直接引用 sortItems 方法。当我添加

import { sortItems } from "vuetify/src/util/helpers";

我收到一个错误“无法解析 'vuetify/src/util/helpers'”。

【讨论】:

    猜你喜欢
    • 2018-09-10
    • 2018-11-25
    • 2013-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-30
    相关资源
    最近更新 更多