Blog-Archiv

Sonntag, 4. September 2022

Sortable Filterable HTML Table with ES6, Part 1

HTML tables do not do very much. If you want to render your data sortable and filterable, you have to implement it by yourself. In this Blog I want to present the result of my efforts to do such. There is no jQuery or react or whatsoever in it, it is just HTML + CSS + ES6 and nothing else.
Mind that this is a client-side action, meaning all table-rows must reside as HTML on the browser-client already. Big paged tables normally are sorted and filtered on server-side.

In this article you'll find just the solution, I will explain the source code in further parts. If you are impatient, simply view the source code of the page (to find the start, search for 'TableHeaderClickHandler').

So what you're seeing below are the 100 highest of Austria's 3242 mountains with a topographic prominence of 100 meters. (Unfortunately the full list was too big for Google Blog:-)

  • Click into the header for sorting and filtering, or navigate with the keyboard (TAB, ENTER, ESCAPE)
  • Sort buttons are right, filter fields are left
  • Filter fields can be closed by erasing the filter input, or clicking the "X" button to the right, or pressing ESCAPE
  • The table should not resize while filtering
  • The header should be sticky on page head while scrolling (might not yet work in MS-Edge, this is the new TABLE feature position: sticky).

Gotcha: the sticky table header has a problem with the separation line down towards the table. No border-bottom style worked, thus I had to give it a background-color.




Keine Kommentare: