How can I hide the sort icons in the header if only one record is selected?
How can I hide the sort icons in the header if only one record is selected?
tradernet
Posts: 2Questions: 1Answers: 0
When a single record is displayed in the table I would like to disable and hide the sort icons in the header that appear next to the heading labels.
Answers
I've never come across this requirement before - could you tell me a bit more about the use case? Why would selected a row cause the sorting indication icons to show or hide?
Allan
Sure, Allan. Let’s say you display several names from a mailing list and use the search field for the name Mike. Now, there is on,y one Mike and his info is displayed in the table, but the sort icons still show which make little sense for just one record. It’s just for a cleaner look and is no big deal. Was just wondering if it was an easy thing to do.
The sorting icons are displayed using :before and :after pseudo elements. One option might be to use the
draw
event to check for the number of rows displayed. Userows()
andcount()
for this. If less than 2 then add a class to hide the pseudo elements via CSS. For example:https://live.datatables.net/pasuqedi/1/edit
I think I found all the pseudo element selectors. If not you can inspect them to find the others.
Kevin