Sort columns by icons
Sort columns by icons
fuqing
Posts: 1Questions: 1Answers: 0
I have a table, some cells contains icons. What I want to achieve here is that when applying sorting on any column, I want the cells with icons to take priority, and to appear either on the top or bottom.
I have noticed that if the cell content is icon + numbers, the sort works exactly the way I want.
However when the cell contains icon + letters, the sort always work in alphabetic order regardless of the icon. Did anyone have a solution for this?
This discussion has been closed.
Answers
You can try the Natural Sorting Plugin. It sorts data with a mix of letters and numbers.
Kevin
You can create your own sorting algorithm with the extension $.fn.dataTable.ext.order.
The next one I use to sort field1 on a fa icon:
And in your table declaration you will do this:
So what you have to do is change the return value
return $(`i`, td).hasClass(`fa-check`) ? `1` : `0`;
to your demands. And of course you can change the namedom-class
as it is only an arbitrary name you are giving to your own sort type.