Live data from Hacker News

Do you know that there is an HTML tables API?

christianheilmann.com

131–140 of 206 posts

Re: Do you know that there is an HTML tables API?

#131

Phew, this post single handedly made me feel old this morning. I started dabbling with the web just over 20 years ago but have mainly been working on the backend the past 10-15 years. I had no clue that nowadays programmers don’t know about this, so I assume it’s supplanted by modern frameworks or modern JS/CSS

I’ve been doing ssr for so long I can’t fathom why you’d build a table using JS.

I've been working on a little SPA that manipulates tabular data and allows the user to insert rows. This is exactly the API I've been using. Like a lot of other commenters it never occurred to me that people wouldn't know this API exists.

Aside: I started with Perl CGI scripts, then ColdFusion, and finally Classic ASP back in the 90s. I had a chuckle a couple years ago dealing with a younger developer who was shocked that and oldster like me was up on new-fangled SSR patterns.

Re: Do you know that there is an HTML tables API?

#132
post #73

Earlier quoted context omitted.

Exactly like how `getElementById` replaced the direct use of the id as a JavaScript identifier.

I remember there being posts that explicitly discouraged using IDs directly, but I'm not sure of tge reasons anymore. Maybe browser incompatibilities or unclear scoping and confusion with other variables?

It works everywhere (it’s now specified in https://html.spec.whatwg.org/multipage/nav-history-apis.html...), but it’s brittle. It can break by adding colliding properties to window deliberately or by accidental global leak (… including things like setting in dev tools), by browser defining new globals, by some 'name' attribute conflict.

Re: Do you know that there is an HTML tables API?

#133

Phew, this post single handedly made me feel old this morning. I started dabbling with the web just over 20 years ago but have mainly been working on the backend the past 10-15 years. I had no clue that nowadays programmers don’t know about this, so I assume it’s supplanted by modern frameworks or modern JS/CSS

It's worth checking who the author is... Cristian's not exactly new to the game. I think he's being humble he doesn't know something despite his experience.

Re: Do you know that there is an HTML tables API?

#134
post #64

Earlier quoted context omitted.

And what does that use internally to manage tables? Just because there is layer between you and the API, it doesn't mean API is abandoned.

Are you implying that when doing DOM reconciliation, React uses these table-specific insertRow/insertCell APIs for adding and removing elements in tables instead of the regular DOM element APIs it would use for all other elements? I would be surprised if that's the case.

The funny thing is the insertRow/insertCell API just call into DOM manipulation functions like appendChild internally, they just provide some syntactic sugar around things like managing the rows/cells array. It's all the same

https://github.com/WebKit/WebKit/blob/28fa568972a4d34d867948...

Re: Do you know that there is an HTML tables API?

#135

Earlier quoted context omitted.

I mean, you can just remove all the user agent styles and then is just as stylable as .

Why would marketing want to pay for the extra (and to their mind entirely pointless) work required to capture semantics? (I’m not saying I like the world we live in, but I don’t see a likely alternative.)

I've literally never had a marketing person tell me whether I should use a or . Let's not pretend things like using the wrong semantic elements is anyone else's fault but lazy or inexperienced developers.

These days it's a moot point anyway, because everyone is using things like tailwind which provide a full reset for things like default buttons, so there really is no excuse.

Re: Do you know that there is an HTML tables API?

#136
post #42

Earlier quoted context omitted.

Yep, didn’t realize this was unknown by enough web developers to warrant an article.

I see new frontend developers using for building buttons, and I've even seen people using for doing titles! Us greybeards don't know how much apparent knowledge we're sitting on, it seems.

In 2004 I was at a company that dedicated a team of people to rebuilding a bunch of tables (lots of financial data) in to styled divs because... "tables are depreciated". The fact that they couldn't pronounce or understand the word "deprecated" should have been enough of a clue to ignore this person, but they were the 'lead' on the web team, and... had been there longer than other people. Obviously they must know what they're talking about. Weeks later after having converted dozens of spreadsheets to divs (instead of just using tables) they were 'done', but it was a tremendous waste of time that ignored all the semantics of tables. I was asked to 'help out' on that project to meet the deadline and refused, citing that it was not just stupid, but a big waste of time and against web semantics.

"table" was never deprecated in HTML at all, but was discouraged for general layout (we were aware of this even in the early 2000s). But for representing tabular data - like... data in rows/columns from spreadsheets (with column headers and such)... HTML tables were absolutely the right (only?) way to present this.

I was at that company less than a year...

Re: Do you know that there is an HTML tables API?

#137

Earlier quoted context omitted.

> Just make sure to pass a subscriber to useSyncExternalStore if you decide to venture outside React and use HTMLTable.insertRow, you see react is really smart and won’t let you use this piece of outdated code without punishing you with side effects. Huh? Why'd you involve state in this or any imperative code? You render the rows/columns as you'd render any other DOM elements in React, pass in the data as props and i…

InsertRow updates the live DOM and React just wholesale replaces it. It’s a masterstroke footgun.

Yes, your point? Anyone who spend 15 minutes learning about React learns that you don't manipulate the DOM directly, you let the rendering engine handle that for you.

Re: Do you know that there is an HTML tables API?

#138

Earlier quoted context omitted.

I see new frontend developers using for building buttons, and I've even seen people using for doing titles! Us greybeards don't know how much apparent knowledge we're sitting on, it seems.

And spans for creating links…

Thereby forgetting that some people like to open links in a new tab.

Re: Do you know that there is an HTML tables API?

#139

> Without having to re-render the whole table on each change. Not quite sure what the author means by that. Re-rendering pnly happens when the current task queue elemt has been processed. Never while JS is running (aside from webworker and the like). I would honestly be surprised if this API had much (if any) performance benefits over createElement.

I quickly looked into the webkit code and there's probably absolutely no performance benefit, the same logic should be running behind the scenes

Re: Do you know that there is an HTML tables API?

#140

Earlier quoted context omitted.

I see new frontend developers using for building buttons, and I've even seen people using for doing titles! Us greybeards don't know how much apparent knowledge we're sitting on, it seems.

And spans for creating links…

I recently discovered our frontend widget library draws an SVG to implement Radio instead of using . I was looking at it because they forgot to add a "disabled" attribute.

Best case I'm hoping it's because they were required to get an exact design, but they really should have pushed back on that one if so.

Post reply on HN