custom-cards / flex-table-card

Highly Flexible Lovelace Card - arbitrary contents/columns/rows, regex matched, perfect to show appdaemon created content and anything breaking out of the entity_id + attributes concept
GNU General Public License v3.0
202 stars 25 forks source link

Wrong sorting if mixed plus/minus values #141

Open Klaestrup opened 1 month ago

Klaestrup commented 1 month ago

If the state can be both plus or minus, it sorts the minus values in the wrong order (like it was plus values).

EdLeckert commented 1 month ago

It certainly does. I'll take a look.

EdLeckert commented 1 month ago

@Klaestrup: Can you confirm that you have non-numeric characters in the states, such as units of measurement? Can you provide a pair of strings that are sorting incorrectly?

Klaestrup commented 1 month ago

I'm using counter values, to show repeating tasks/reminders: entities: include: counter.reminder* sort_by: state+ And the values are shown like this: image

I was thinking of using flex-table-card instead of template-entity-row, but I'm missing the tap_action feature here. Is it possible somehow to preset the counter to its initial value with a push on the row? In template-entity-row I'm using the confirmation text, so that you have to confirm that it's the correct counter that you want to preset.

EdLeckert commented 1 month ago

As I suspected, it's the non-numeric text "dage" that causes the failure--the algorithm does not treat the value as numeric. I have a fix for this problem, which I could provide to you while we wait for the code owner to respond to pull requests. But if the component doesn't meet your needs in other ways it may not be worth your trouble.

There has been some discussion about adding actions to the component, but nothing has been done yet.

Klaestrup commented 1 month ago

But 'dage' is not a part of the state, but a suffix (suffix: ' dage'). Then I don't expect that it's sorted on this also...?

EdLeckert commented 1 month ago

OK, I thought you were using auto_format. You are correct: suffix is not part of the sort.

Do you mind posting your entire card config?

Klaestrup commented 1 month ago

Here it is, but I don't know how to post it correctly. The "Code" button does not support YAML! :-p

type: custom:flex-table-card title: Opgaver sort_by: state+ clickable: true entities: include: counter.reminder* card_mod: style: | div { padding: 4px; } css: table+: 'border-collapse: collapse;' th+: 'padding: 8px;' td+: 'padding: 16px;' columns:

EdLeckert commented 1 month ago

Just paste it, select all, press the Code button:

type: custom:flex-table-card
title: Opgaver
sort_by: state+
clickable: true
entities:
  include: counter.reminder*
card_mod:
  style: |
    div {
      padding: 4px;
    }
etc.

So your issue is essentially the same as #129. Your HTML or anything added by modify becomes part of the sort, and is no longer treated as a numeric but as text. I will see if I can get a PR pushed through to deal with it.