Live data from Hacker News

Do you know that there is an HTML tables API?

christianheilmann.com

11–20 of 206 posts

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

#11
post #7
post #2

Tables died (thankfully) to make room for flex and grid. I can't see any use case for them at all anymore.

Tabular data? Tables have a purpose, it's just that people misused them for layout purposes.

To be fair, we did that when there wasn’t much choice for laying out web pages other than using tables. I was there!

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

#12
post #4
post #2

Tables died (thankfully) to make room for flex and grid. I can't see any use case for them at all anymore.

I personally disagree. When data is semantically a table, not just a “table-looking” layout, I would rather use the table tag.

I think this is the gist of it. Tables were abused as general spaced 1D, and 2D styling components. Introducing proper general spacial styling components means we don't need to extend tables beyond their original purpose, but doesn't mean we shouldn't use them for that purpose!

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

#13
I was using it just half a year ago, after either reading MDN or reading what AI suggested. Which means, this API is not obscure and not forgotten. Using `rows` and `cells` is very convenient for keyboard navigation across table cells.

https://github.com/ClickHouse/ClickHouse/blob/master/program...

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

#14
post #7

Earlier quoted context omitted.

Tabular data? Tables have a purpose, it's just that people misused them for layout purposes.

To be fair, we did that when there wasn’t much choice for laying out web pages other than using tables. I was there!

Especially in ways that worked cross browser.

Young folk don't understand just how wildly different IE5 was to the Netscape or the Mozilla browser. Or just how bad Javascript was when it started to be used on the internet.

I've lived through and seen the evolution. For all the shit the JS community takes for constantly revving frameworks, it's 1000x easier to make a website that looks the same regardless of browser due to a lot of these frameworks and browsers themselves evolving.

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

#15
Interesting, but the JavaScript examples hurt:

    let table = [
      ['one','two','three'],
      ['four','five','six']
    ];
    let b = document.body;
    let t = document.createElement('table');
    b.appendChild(t);
    table.forEach((row,ri) => {
      let r = t.insertRow(ri);
      row.forEach((l,i) => {
        let c = r.insertCell(i);
        c.innerText = l;  
      })
    });
Use full words for variable names!

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

#16
The variable naming convention used here could be improved for clarity. I prefer appending `El` to variables that hold DOM elements, as it makes identifiers like `tableEl` clearer and helps avoid ambiguity between variables such as `table` and `row`. Also, the variable named `table` does _not_ actually represent a table element; it would be more accurate to name it `data` or `tableData` to better reflect its purpose.

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

#17
post #15

Interesting, but the JavaScript examples hurt: let table = [ ['one','two','three'], ['four','five','six'] ]; let b = document.body; let t = document.createElement('table'); b.appendChild(t); table.forEach((row,ri) => { let r = t.insertRow(ri); row.forEach((l,i) => { let c = r.insertCell(i); c.innerText = l; }) }); Use full words for variable names!

I was just about to comment the same. I’m sure people have a good reason for it (or at leafy _a_ reason), but single-letter variable names always struck me as optimizing for the wrong thing.

As someone who likes to program in Haskell, I feel this pain very strongly. :)

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

#18
post #2

Tables died (thankfully) to make room for flex and grid. I can't see any use case for them at all anymore.

They’re probably still quite useful for displaying tabular data - there’s also semantics involved, it’s not primarily just a layout mechanism.

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

#19
post #15

Interesting, but the JavaScript examples hurt: let table = [ ['one','two','three'], ['four','five','six'] ]; let b = document.body; let t = document.createElement('table'); b.appendChild(t); table.forEach((row,ri) => { let r = t.insertRow(ri); row.forEach((l,i) => { let c = r.insertCell(i); c.innerText = l; }) }); Use full words for variable names!

Really? The variable name lengths? Not that the code is clearer as:

    const te = document.createElement('table');
    document.body.appendChild(te);
    [
        ['one',  'two',  'three'],
        ['four', 'five', 'six'  ],
    ].forEach((r, i) => {
        const re = te.insertRow(i);
        r.forEach((c, j) => {
            re.insertCell(j).innerText = c;
        })
    });
My personal stance on short variable names is that they are fine as long as their scope is very limited, which is the case here. Rather, the "crime" to me is an overuse of rather pointless variables as the majority of them were only used once.

Disclaimer: I have not tested the code and I only write JavaScript once every few years and when I do I am unhappy about it.

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

#20
post #15

Interesting, but the JavaScript examples hurt: let table = [ ['one','two','three'], ['four','five','six'] ]; let b = document.body; let t = document.createElement('table'); b.appendChild(t); table.forEach((row,ri) => { let r = t.insertRow(ri); row.forEach((l,i) => { let c = r.insertCell(i); c.innerText = l; }) }); Use full words for variable names!

I was just about to comment the same. I’m sure people have a good reason for it (or at leafy _a_ reason), but single-letter variable names always struck me as optimizing for the wrong thing. As someone who likes to program in Haskell, I feel this pain very strongly. :)

Do you always feel this is the case? To me the go to single letter variables are very readable. Used so widely my eyes parse them like other symbols: =, &, +, etc.
Post reply on HN