Closed riker09 closed 5 years ago
I think I could just split the JSON payload to different attributes (e.g. diesel
, e5
, distance
, ...) and then use that as value for attr_as_list
, but that feels like the wrong way to go.
mmh, yes the "modify" attribute was initially intended as a formatting operation, thus it is applied after sorting was done. It would actually not be a big deal to move it, but I am currently not fully convinced if this might not break something---or at least change the behavior for most people using modify and sort together. I'll first move it, push it in a branch then you can check if it behaves as you would expect....
ahhhh, noooo, forget what I've written there, my code confuses me sometime if I haven't seen it for more than 1hour :smile:
The problem is---as you also already implied---that the correct column can simply not be identified for sorting, thus all are sorted as they are all identified with the same identifier, namely stations
here.
Once understood this is easy to fix, I'll just add the possibility to override the implicit identifier derived from the attr_to_list
parameter.
hope it works for you, literally one single word added to make it work from functional point of view. Anyways like how you "exploited" the modify param, this cries for a json param to provide a more specific solution for exactly this use-case.
If the id
solution works for you, feel free to close the issue,
thanks
btw. think you just would have to change your config like this:
sort_by: diesel_price-
...
columns:
...
- name: Diesel
attr_as_list: stations
id: diesel_price
modify: Math.abs(x.diesel).toFixed(2)
Keep in mind that toFixed()
will convert to a string, means string-sorting applies and not number-based sorting (likely not an issue for diesel). To avoid this problem you could just add another hidden column without toFixed() and sort by this one, while this column here would be its string representation.
I cannot test the changes right now (worky, worky) but I'll look into them later. Hopefully today.
Okay, haven't had the time to check it out yesterday. But today: Great success!
Thank you very much!
First of all thank you for this great custom card. I think it is really useful and has a lot of potential. Not all data fits into a colorful bar/pie/line chart, some things make perfect sense in a table. :slightly_smiling_face:
Now, as discussed in issue #4
flex-table-card
supports the attributes of a sensor. I query an API that gives me gas prices of some nearby gas stations (diesel + e5). The sensor name issensor.gas_prices
and the attribute name isstations
and the payload I read with Jinja template{{ state_attr("sensor.gas_prices","stations") }}
looks like this:And sure enough I can display the values in a table with this YAML config:
But how can I sort on, let's say, the diesel price? Looking at the code it seems that only sensor attribute names are supported. It looks for a value in the
attr
,prop
orattr_as_list
field, but the latter always hasstations
as a value.