Sort Table by click in header tag regardless of it is numeric, alphabetical or date

后端 未结 2 386
悲&欢浪女
悲&欢浪女 2020-12-12 06:48

I\'m trying to sort my table by javascript(only javascriptpure, not library and not framework, only javascriptpure).

Each column sort by clicking in every header tag

2条回答
  •  自闭症患者
    2020-12-12 07:23

    What you want is most likely a natural sort. Where you can sort on alphanumerics, "naturally". There are a myriad of options out there on npm that you can use as reference. The first hit on google is javascript-natural-sort. This should point you in the right direction.

    Once you have that, I would bind an event handler to your table header, which passes along the column name you wish to .sort() on, then natural sort your places array based on that key, then rerender the table.

提交回复
热议问题