The Datatables sort icon, on column headers, by default appears under the column header text. I'd like to have this appear on the same line and on the far right side or far left side of the header cell.
Here's how the HTML for one of the column headers appears (in Firebug).
<th class="ui-state-default" rowspan="1" colspan="1" style="width: 252px;">
<div class="DataTables_sort_wrapper" style="text-align: left;">
Account Name
<span class="DataTables_sort_icon css_right ui-icon ui-icon-triangle-1-n"></span>
</div>
</th>
I added display: inline-block;
to the css-right
class on the <span>
to force it to appear on the same line as mentioned here and here. However, I still can't find how to force the icon to appear on the far right or the far left. Adding float:left;
or float:right;
bumps the icon to the next line.
Any ideas?
I don't know if this is the best way, but here's what I see in my jQuery-UI DataTable for that symbol:
From the site's main stylesheet (not part of the jQuery UI stylesheet):
.display thead th .DataTables_sort_wrapper span { float: right; }
From the jQuery UI CSS file:
There are some other styles of course, but I think those are the ones that matter. Based on your question, I'm surprised it's not already working for you.
For me
table.display
did not exist, I added the following:The above worked for me.
For the latest version of Datatables(as of 31 march 15). inside the datatables CSS change the following-
Though Greg's answer lead me to the solution (and is the answer I accepted), for clarity, and as a help to others that might run into this issue, I'm adding my own answer.
What most affects the positioning of the sort icons is this default DataTables CSS:
If the
class="display"
attribute is not on the table, the CSS above is not applied.The problem being, Datatables [often] places the sort button under the text.
The OP specifically wanted the button on the right or the left of the text; however, Steve Teale of http://britseyeview.com/ has a solution which moves the sort buttons up above the text and to the top-right of the cell. Meaning, the sort button is always top-right, but sometimes over the text. Basically he resets the original CSS.
You will need to add your path to the "background: url('/your/path/sort_both.png')".
Steve's "Getting Started with Datatables" is here: http://britseyeview.com/software/dtgs/