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

[FR] Sorting: use a "raw" value instead of "modified" #129

Open
ildar170975 opened this issue Feb 3, 2024 · 1 comment
Open

[FR] Sorting: use a "raw" value instead of "modified" #129

ildar170975 opened this issue Feb 3, 2024 · 1 comment

Comments

@ildar170975
Copy link
Contributor

ildar170975 commented Feb 3, 2024

Consider smth like:

type: custom:auto-entities
filter:
  include:
    - domain: automation
      sort:
        count: 5
card:
  type: custom:flex-table-card
  columns:
    - name: name
      data: name
    - name: last_triggered
      data: last_triggered

изображение

We may sort the table by clicking.
Let's sort by "last_triggered":

изображение

So far it works OK.

Now assume I need to apply modify for this last_triggered column:

type: custom:auto-entities
filter:
  include:
    - domain: automation
      sort:
        count: 5
card:
  type: custom:flex-table-card
  columns:
    - name: name
      data: name
    - name: last_triggered
      data: last_triggered
      modify: >-
        if (x) {
          if(x.length == 0){
            "-"
          }
          else {
            if (x != "н/д") {
              var date = new Date(x);
        
              (String(date.getDate()).padStart(2,'0')) +
              "/" +
              (String(date.getMonth()+ 1).padStart(2,'0')) + 
              "/" +
              date.getFullYear() +
              " " +
              String(date.getHours()).padStart(2,'0') +
              ":" +
              String(date.getMinutes()).padStart(2,'0') +
              ":" +
              String(date.getSeconds()).padStart(2,'0')
            }
            else {
              "-"
            }
          }
        }
        else {
          "-"
        }

изображение

And now sorting works in a wrong way - it sorts MODIFIED strings:

изображение

Proposal:
add a per-column option like sort_by_raw (boolean):
false - use a modified string for sorting,
true - use a raw (untouched) string for sorting.


Current workaround - use another modifier which creates "sortable" strings starting by "YYYY/MM/DD":

if (x) {
  if(x.length == 0){
    "-"
  }
  else {
    if (x != "н/д") {
      var date = new Date(x);

      date.getFullYear() +
      "/" +
      (String(date.getMonth()+ 1).padStart(2,'0')) + 
      "/" +
      (String(date.getDate()).padStart(2,'0')) +
      " " +
      String(date.getHours()).padStart(2,'0') +
      ":" +
      String(date.getMinutes()).padStart(2,'0') +
      ":" +
      String(date.getSeconds()).padStart(2,'0')
    }
    else {
      "-"
    }
  }
}
else {
  "-"
}
@ildar170975
Copy link
Contributor Author

ildar170975 commented Feb 3, 2024

This is only crucial for a "sort by a header" use case.
For a "static" (fixed) sorting we may just sort by a hidden column with "raw" data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant