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?

tradernettradernet 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

  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin

    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

  • tradernettradernet Posts: 2Questions: 1Answers: 0

    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.

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974
    edited February 18

    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. Use rows() and count() 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

Sign In or Register to comment.