Sortable column with anchor in header?
Sortable column with anchor in header?
jrichview
Posts: 36Questions: 7Answers: 0
So, in my grid almost all columns are sortable, but my header text is always an anchor. If you click the anchor the column both sorts and follows the anchor link.
What's the best way to disable the sort in the case when the user has clicked the actual anchor, not somewhere in the rest of the header?
This discussion has been closed.
Answers
You'll likely need to unbind the sort event from the headers and bind it to those specific a tags
Example legacy code http://datatables.net/forums/discussion/16095/sorting-using-external-buttons-for-asc-and-desc
And the newest function reference below.
http://datatables.net/reference/api/sort()
jQuery unbind
http://api.jquery.com/unbind/
http://api.jquery.com/off/
And some references on how to unbind the click event from the
<th>
tagsunbind click events
http://datatables.net/forums/discussion/3638/disable-sorting-when-clicking-on-headers
http://datatables.net/forums/discussion/9168/capturing-user-clicks-on-column-headers
I actually DO want the th tags to sort. But when you click on the anchor tags, I just want it to act like an anchor, not try to sort while the anchor click is being processed. So I don't want that event bound to the anchor tags.
I'll take a look at this, though. Maybe it will get me going in the right direction. Thanks!