jennschiffer / timbles.js

a very simple jQuery plugin for tables, made by the person who literally did not invent tables
MIT License
38 stars 4 forks source link

Fix pagination sort and enabling #26

Closed edelooff closed 8 years ago

edelooff commented 8 years ago

This PR brings two improvements to pagination. It resolves #24, allowing a script (or user) to enable pagination (via the enablePagination method) after timbles has been initiated on the table.

Secondly, it resolves #25 by not placing off-page rows on the DOM. For my 2300-row test table, with a page size of 100 rows, this means the sorting time is down from roughly 200ms to about 20ms.

Code-wise the following changes have been made:

Tests for pagination will follow some other time.

edelooff commented 8 years ago

Turns out the 10x speedup I mentioned is a bit exaggerated. The following is a result from playing with the Timeline from the Chrome dev tools. Values are averages over 10 sort clicks on the same column (and the cpu set to performance to remove some noise):

Old Code

New Code

Somewhere around an average 4x speedup for reasonably paged results.

The code in goToPage is a bit slower than the detached table body which inserts all rows, so with a sufficiently large page size, it will end up being slower. However, detaching and re-attaching the body also comes with overhead, which would affect typical small page size. And even at 1000 rows per page, the new code is a good bit faster :smiley:

jennschiffer commented 8 years ago

:ship: :santa:

looks/works great!