Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Report][3.5.2] VDataTable sort should use the value of the column #19159

Closed
moltinginstar opened this issue Feb 2, 2024 · 1 comment
Closed
Labels
duplicate The issue has already been reported

Comments

@moltinginstar
Copy link

Environment

Vuetify Version: 3.5.2
Vue Version: 3.4.15
Browsers: Chrome 121.0.0.0
OS: Mac OS 10.15.7

Steps to reproduce

Click a column to sort by, you will see the value used by sort.

Expected Behavior

sort should use the computed value of a column if value is a function.

Actual Behavior

sort receives item[key] instead, which is either undefined or the wrong value.

Reproduction Link

https://play.vuetifyjs.com/#...

Other comments

As a workaround I’m forced to extract the value functions into a map,

const values = {
  fullName: (item) => $t("full-name", {
    first: ts(item.name.first),
    middle: ts(item.name.middle),
    last: ts(item.name.last),
    age: item.age,
  }),
  views: (item) => item.stats?.views ?? null,
  ...
} satisfies {
  fullName: (item: Account) => string;
  views: (item: Account) => number | null;
  ...
};

so I can reuse them in my reimplementation of sort (using the newly added sortRaw):

const headers = [
  {
    title: $t("header.full-name"),
    key: "fullName",
    value: (item) => $t("full-name", {
      first: ts(item.name.first),
      middle: ts(item.name.middle),
      last: ts(item.name.last),
      age: item.age,
    }),
    sortRaw: (a, b) => {
      const aValue = values.fullName(a);
      const bValue = values.fullName(b);

      return aValue.localeCompare(bValue);
    },
  },
  ...
];

What I would like to be able to do is define the value of each column once and have the default implementation of sort use that value instead of item[key].

@KaelWD
Copy link
Member

KaelWD commented Feb 4, 2024

Duplicate of #18840

@KaelWD KaelWD marked this as a duplicate of #18840 Feb 4, 2024
@KaelWD KaelWD closed this as not planned Won't fix, can't repro, duplicate, stale Feb 4, 2024
@KaelWD KaelWD added the duplicate The issue has already been reported label Feb 4, 2024
@github-actions github-actions bot removed the S: triage label Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate The issue has already been reported
Projects
None yet
Development

No branches or pull requests

2 participants