News for hackers. Stuff that matters.
Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by ohitsdom on Friday November 30, 2018 @08:22AM (#18568848)
It seems standard that all of these JS table libraries are rendering using <div> elements instead of a <table> element. Why? This really irks me. As far as I can tell, all of the features could be implemented using the correct HTML element rather than using <div> to mimic a table.
Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by olifolkerd on Friday November 30, 2018 @09:40AM (#18569389)
Let me preface my answer by saying im the chap that built Tabulator

This is because the <table> element introduces a lot of design constraints.

There is a lot of inhernt styling that would have to be overridden if a table element was to be used. it could also mess with the standard behaviour of other table elements that have been generically styled.

Importantly when you start building interactive complex tables there are 100's of different types of elements needed to make the table function correctly that a standard HTML element simple isn't designed to handle, event making the header and the body scroll separately requirements more elements that a standard table can handle and it would invalid HTML to use the tags inside the table that would be needed to achieve it.

Especially when you move into the world of the virtual DOM a standard table element simply wont cut it

With the inclusion of aria tags there are no accessibility issues as screen readers treat them just as any other tables.

Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by Rumudiez on Friday November 30, 2018 @02:11PM (#18571722)
For others; your last point is the most important. Semantic HTML gets you pretty far but there will always be an unhandled case. This is a fine use case of ARIA as long as it’s met with sincere concern for accessibility testing.
Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by ohitsdom on Friday November 30, 2018 @02:56PM (#18572089)
Appreciate the details. I've done some minor JS-based table controls while using <table>, but I wasn't dealing with thousands of rows so didn't need the virtual DOM. Sounds like that's the biggest obstacle. Nice work on the project!
Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by damntrecky on Friday November 30, 2018 @04:14PM (#18572683)
For the nested markup and styling it sounds like a perfect fit for creating a web component no?

The virtual DOM, while very impressive, isn't necessary as well. Really depends on what problem you are solving there and what level of support you need for browsers. What problem are you solving? Many entries? Minimal cell mutation control?

Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by olifolkerd on Friday November 30, 2018 @04:26PM (#18572783)
For Tabulator the virtual DOM is essential. if you try and load 10,000 rows into a table either the browser will slow down and become almost unusable or crash entirely.

For large data sets it makes the table work regardless of the number of rows

Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by derefr on Friday November 30, 2018 @05:09PM (#18573170)
What if you just chunk your DOM writes into small batches, and then put them into a queue, which is then consumed within a requestAnimationFrame() handler? A bit of indirection, but not nearly as much as a complete virtual DOM. (I assume this would result in the table "slowly" populating, but the browser and the page should both remain responsive.)
Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by olifolkerd on Friday November 30, 2018 @05:16PM (#18573226)
You can can do this but for large data sets it would take ages and doesnt over come the main issue.

Lets say we are working with 10,000 rows

Yes loading that many elements into the DOM is slow and your approach would stop it blocking, however what it dosnt do is stop the sheer number of elements from overloading the DOM.

Most browsers simply cant handle that many elements in the DOM, if you try and scroll a div containing that may elements at best it will be sluggish and at worst it will simply crash the browser. on devices without much memory it is very likely that the whole DOM will freeze up and make the site unusable.

By adding and deleting the elements as they become visible/hidden it keeps the number of elements in the DOM to a minimum, while improving load time and adding only a bit of extra processing to the scroll event, which modern browsers can handle with ease. giving all round the best solution

Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by derefr on Friday November 30, 2018 @05:23PM (#18573289)
Ah, I didn't realize that "culling" of non-viewport-visible divs happened within your vDOM implementation. I agree that that would need to happen either way. If the "culling" process was a separate layer, though, it could also be implemented on top of the DOM-queuing process I mentioned.

I did this myself when writing a chat client's infinite history scrollback. Chat messages that aren't on the screen still have a pure-data "event" representation of them loaded, but their DOM representation (virtual or otherwise) is entirely discarded. Rather than the physical DOM nodes for chat-message divs having fixed positions such that they're able to disappear without affecting their peers' layout, I instead just have the chat messages stacked as regular block elements under reflow, with two fixed-size "scroll pad" divs just above and below the viewport "consuming" and "releasing" the vertical height that had been taken up by message divs as they're added and removed. You can have millions of rows "loaded" (in the sense of parsed data sitting in JS memory) for instant access, with not much browser memory usage at all.

Though, even that memory usage was too much (this chat client is supposed to run beside memory-intensive apps like games), so as well, in my setup, nodes that are far enough off the screen can have their parsed "event" representation discarded, and replaced with a single URL representing the serialized "history chunk" that those events came from. When the scroll distance comes close to them, the chunks are reloaded by re-requesting and re-parsing the chunk (which, helpfully, is usually still in the browser cache.)

Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by warpech on Friday November 30, 2018 @08:53AM (#18569090)
Author of another library, Handsontable, here. We actually use <table>, but there are many things that are easier with <div>:

- With <div>, you have complete control over the positioning of the cells. With <table>, you delegate the layout to the browser engine. - <table> has lots of semantic meaning, which makes it slower to render than a <div>, because the browser engine needs to make a sense of it. - There are differences in how <table>s are rendered in various browsers. This is especially a problem with old browsers such as IE6. - It is trickier to implement things like floating headers, virtual scrolling with <table>

Still, Handsontable uses <table> because you can overcome these problems if you're motivated enough. The biggest benefit is that <table> gives you enhanced semantics, which are good for Accessibility, SEO or any other form of code processing.

Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by BjoernKW on Friday November 30, 2018 @10:04AM (#18569545)
In addition to that, using <table> gives you out-of-the-box Excel file export because .xlsx files (which are basically zipped XML files) support HTML tables.
Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by TeMPOraL on Friday November 30, 2018 @10:59AM (#18569974)
> <table> has lots of semantic meaning, which makes it slower to render than a <div>, because the browser engine needs to make a sense of it.

I have to ask: is this really slower overall? I didn't try to make an exact 1:1 comparison, but in my experience, all JS-powered table libraries I've seen start choking around a couple hundred elements. With HTML tables + minimal styling, I can dump 10k+ rows with no performance penalty.

Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by warpech on Friday November 30, 2018 @03:11PM (#18572187)
<table> element is much more complex to process than a <div>. <table> is one of the few elements that actually have a dedicated "Processing model" section in the spec: https://www.w3.org/TR/html52/tabular-data.html#tabular-data-...

It is not neccessarily a bottleneck, as long as your datagrid library uses the browser's ability to render the table. But if you want a custom look and feel, such as overlapping cells, irregular shaped cells, animated cells, it's far better to do it based on <div>s instead of fighting the browser engine.

Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by olifolkerd on Friday November 30, 2018 @11:01AM (#18569987)
This is why you need to use a virtual DOM to prevent the DOM from being filled with elements that consume memory and slow it down
Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by mattnewton on Friday November 30, 2018 @12:06PM (#18570499)
Don’t know why you are being downvoted- it’s a real technique to render only a subset of elements that fit on ~2 screen lengths and swap them out as the user scrolls for arbitrarily large tables. Just using virtual dom doesn’t magically solve this but it does make doing things like this parlor trick easier IMO.
Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by TeMPOraL on Friday November 30, 2018 @12:12PM (#18570545)
And yet I can't shake the feeling that this is part of the problem, not the solution. I have never seen a site using vDOM that didn't feel slow. That includes everything using React that I've seen or made. It might be that the performance loss comes from excessive styling and unrelated superfluous JS, but I'd love to see some analysis on the performance overhead of just the vDOM.
Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by olifolkerd on Friday November 30, 2018 @12:33PM (#18570715)
vDOMs do carry a fairly significant performance overhead and they are not worth using where there is only a small amount of data to be handled (which is why it can be turned of in Tabulator if not needed) but on modern browsers it isnt really something you should be noticing.

But when you start dealing with large volumes of data they quickly become the only option.

Even a plain html table with say 10 columns will crash out /massively slow down a browser if you load in 100,000 rows of data.

Browsers simply aren't able to process that may elements being added to the DOM.

In the case of Tabulator you can handle many thousands of rows because it only adds the rows you can see to the DOM, removing/adding them as you scroll.

So yes this means there is more processing when you scroll but at the same time you aren't trying to move 100,000 od DOM elements at once which reduces the load on the browser when loading/scrolling.

Depending on the complexity of what you are dealing with there becomes a point where the trade off in processing/memory usage makes it worthwile

Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by lazyasciiart on Friday November 30, 2018 @12:27PM (#18570667)
Do you check source on every page you see, or just the ones that feel slow?
Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by ergothus on Friday November 30, 2018 @11:31AM (#18570237)
> + minimal styling

I suspect that may be the primary reason, not JS. When you start juggling details that impact a cell, that in turn impacts all the rest of the table, so you can add up with an additive impact based on the number of cells. <divs> still have that, but actually fall under the well-optimized engine for rendering, well, divs (and other straightforward elements that only impact other elements via positioning, not by things like colspan and rowspan)

But this is speculation on my part. I can say that while I appreciate the semantic definition of table and use the tag appropriately in my own work, I never look forward to it because it's always more work than doing so with divs. There is a reason everyone was happy to leave table-based layout behind and it wasn't (just) a desire for semantic purity.

Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by olifolkerd on Friday November 30, 2018 @10:13AM (#18569629)
Tabulator uses aria tags to let screen readers and other accessibility tools know how the table is structured so it is still just as accessible as a normal table even with its increased complexity
Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by itodd on Friday November 30, 2018 @02:47PM (#18572028)
Just want to say thanks for handsontable. Thanks. It is a great way for my users (scientists who live in Excel) to feel comfortable with the applications we make to help them discover new therapeutics more efficiently.
Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by warpech on Friday November 30, 2018 @02:57PM (#18572094)
You're very welcome! I am happy to hear it is used to make the World a better place :)
Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by twanvl on Friday November 30, 2018 @09:13AM (#18569211)
Could use use <table> for the semantics but set display:block to get <div> style layout?
Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by olifolkerd on Friday November 30, 2018 @10:21AM (#18569684)
the problem is it isnt just the table element, it is the thead,tbody,td,th elements as well

Complex interactive tables need a great number of elements to make them run and these wont conform to the standards of using a table (you cant just put a div inside a tbody element) but that is exactly what you would need to to to get a table with a virtual DOM to work correctly.

There are a lot of different styling tweaks that would need to be overriden for each element, some of which arnt consistent across each browser.

Also people have a tendency to put styles on the generic table tab to style tables across the site. if Tabulator was to then be used on the page, it could have any number of unknown CSS properties set on it, so would essentially have to look at overriding all possible style properties.

where as no one generically styles divs or spans and they come with very little built in styling making them the ideal choice for a library that wants to keeps its functionality isolated from the rest of the site

Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by lunchables on Friday November 30, 2018 @09:08AM (#18569178)
I've worked with datatables quite a bit and it uses standard table tags: https://datatables.net/
Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by noir_lord on Friday November 30, 2018 @07:16PM (#18574029)
That's what I use at work, I just wrapped it with Vue and did some moderately horrible stuff internally to allow reactive rendering (and by moderately I mean horribly).

Performance is solid, it's easy to work with for ~90% of the times I use it and there are other ways to handle that last 10%.

I probably wouldn't have used datatables on greenfield but the legacy (in every sense) project I inherited already used it so I went with it anyway.

Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by kgwxd on Friday November 30, 2018 @09:54AM (#18569475)
Try it, it doesn't take long to figure out there's no good way to do even basic features without fighting very hard against the built-in behavior of tables. Also, for even just 1000 rows, all browsers still suck at redrawing if any little thing changes, I believe it's because the entire layout of the table has to be recalculated no matter how small the change is.
Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by olifolkerd on Friday November 30, 2018 @10:12AM (#18569608)
Spot on!, Tabulator uses a virtual DOM to get round the limit on the number of rows, and that simple isn't achievable in a standard table element
Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by djaychela on Friday November 30, 2018 @08:37AM (#18568959)
I'm certainly not an expert (beginning Python programmer who knows very little about Javascript), but I thought it was because divs can be responsive and tables can't be, but I'm prepared to be corrected on that.
Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by EMRZ on Friday November 30, 2018 @08:53AM (#18569084)
I work as a developer in a trade marketing company, our platform have dashboards with different type of charts for our clients to measure different metrics of their business.

The front end requests to the backend each chart on the current dashboad, then the backend, depending of the type of chart, gets the data from the database and passes it to the front who renders it, it could be a pie chart, a bar chart, a table, etc.

We hade 2 or 3 different types of table charts, al using different js based solutions, one of them using bootstrap, i don't remeber the others.

The javascript solutions had responsiveness issues, when you changed the size of the window, or used something that is not Chrome, column headers messed everything up.

One day i decided to end that and added a new type of chart, it expected one table resultset from the db, and once in the front it rendered a traditional <table> with it's content.

We have no more problems with table charts. It works in every browser and every screen resolution.

It was possible to fix the current js tables of course, but is it realy necessary? We have been using tables since forever, and they are just to correct way to display table data on the web.

Thats it, it just works.

Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by JangoSteve on Friday November 30, 2018 @01:08PM (#18571051)
There are many ways to make HTML tables responsive:

https://css-tricks.com/responsive-data-tables/

Re:Show HN: Tabulator – Easy-to-use JavaScript library for i... by JangoSteve on Friday November 30, 2018 @01:05PM (#18571020)
A library I built called Dynatable doesn't do that! It uses semantic, standard table elements for all serializing and rendering of tabular data.

We've since rewritten Dynatable to use vanilla JS and are in the process of renaming it to simply Dynatable instead of jQuery Dynatable.

https://github.com/alfajango/jquery-dynatable

https://www.dynatable.com/