simonw / datasette-cluster-map

Datasette plugin that shows a map for any data with latitude/longitude columns
Apache License 2.0
87 stars 16 forks source link

Map fails to render if table is sorted by latitude or longitude #18

Closed simonw closed 4 years ago

simonw commented 4 years ago

e.g. https://global-power-plants.datasettes.com/global-power-plants/global-power-plants?_sort=latitude

simonw commented 4 years ago

Here's why: https://github.com/simonw/datasette-cluster-map/blob/80f2ffcd91cb2f9a883f980f860347f9f6d7a3cd/datasette_cluster_map/static/datasette-cluster-map.js#L4-L8

On the table that displays the bug that looks like this:

[
    "Link",
    "rowid",
    // ...
    "capacity_mw",
    "latitude ▼",
    "longitude",
    "primary_fuel",
    // ...
]
simonw commented 4 years ago

The next release of Datasette adds a new data-column attribute which could help fix this:

<th class="col-pk" scope="col" data-column="pk" data-is-pk="0">                          
  <a href="/fixtures/facetable?_sort_desc=pk" rel="nofollow">pk&nbsp;▼</a>
</th>
simonw commented 4 years ago

I can fix the plugin right now to detect if data-column is available and, if not, to fall back on th.textContent.trim().