Tuesday, 17 October 2017

Fast table order with jQuery

Ordering tables is a common thing. It can be solved with two ways. First one is server-side, while is selecting from database in the right order and limit. Second option is javascript solution on user-side, in his browser. Second solution is good for smaller tables and exists many libraries or scripts to achieve that.

I met personally a problem with bad optimization of this libraries and while I was trying this on bigger table, my browser just freeze. I didn't give up and I created own script aimed on performance and speed. This solution keeps all needed functions.

I needed to solve some problems while I was developing it, I will not going deep right now. Main goal was a speed, that is a reason why is available a debug variable for testing purpose. Biggest slowdown was created by jQuery detach. It's important because his function is keep binded events. At the end I figured out when I put existing element to the page, this function is not important, it's just moving origin elements.

Whole code is available here: https://bitbucket.org/snippets/EsoLDo/7Edz/sort-table-jquery

Ordering supports both directions and data types integer, string and date. Detection of integer is automatic. Needed information for implementation is at the top of code as a comment.

If you like this solution, you can support me

No comments:

Post a Comment