Sorting arrow not showing.
Sorting works, but I do not see the arrow, What am I missing?
when you click on a header with the st-sort directive a class name is added/removed so you can set the style you wish. On the demo site (the arrows) are done with
.st-sort-ascent:before{
content: '\25B2';
}
.st-sort-descent:before{
content: '\25BC';
}
you can also change the classname if you want (if you use a css framework for example):
set the attributes st-sort-ascent="ascent class name" and st-sort-descent="descent class name"
Thank you, it works!
Hi - is there a reason the arrow styling isn't included with the library? It's confusing to have the arrow styling on the demo site but not available with the lib. Would be willing to submit a PR if you'd be open to including it. Thanks for your work on this - by far the best table directive I've used!
Hi, I prefer not to include it with the library so there is no css file and anyone can set its own, it is not a lot of work anyway if one wants to use the demo website style. Just need to find this issue ;)
Thanks for your interest,
Laurent.R
Hello, Maybe you should state that fact about styles in tutorial? I think it would save some time for a lot of people.
Anyway, thank you for your plugin :)
Yep, promise I will mention it during the next documentation write up. Note you can still press the button "improve this documentation" ;)
regards,
Laurent R
Thanks for the excellent explanation. I'd like to ask more: If I want some other content to be shown in its default state. How to do that?
I've tried the following code, but seems not to work.
<style>
.st-sort-default:before {content: '\25B1'}
.st-sort-ascent:before {content: '\25B2'}
.st-sort-descent:before {content: '\25BC'}
</style>
<table st-table="data">
<thead>
<tr>
<th class="st-sort-default" st-sort-ascent="st-sort-ascent" st-sort-descent="st-sort-descent"
st-sort="startTime" st-sort-default="reverse">Start Time</th>
<th class="st-sort-default" st-sort-ascent="st-sort-ascent" st-sort-descent="st-sort-descent"
st-sort="id">ID</th>
<th class="st-sort-default" st-sort-ascent="st-sort-ascent" st-sort-descent="st-sort-descent"
st-sort="name">Name</th>
</tr>
</thead>
<tbody>...</tbody>
</table>
@stanleyxu2005 I have the exact same question. Actually, there is no class added in the default state. So, I think we have to manually detect whether there is a class added in an element or not. If not, that means the default state. However, it's quite a trivial task. :(
@lvarayut After reading the source code, I understand why the author makes it so simple. And here is my solution. I prefer to add the sort arrows right to text. (If column text is right aligned, it'd be better to move arrows to the left)
<style>
.sortable { cursor: pointer;}
.st-sort-ascent i,.st-sort-descent i { padding-left: 4px;}
.st-sort-ascent i:before { content: '\25B2';}
.st-sort-descent i:before { content: '\25BC';}
</style>
...
<tr class="sortable">
<th st-sort="id" st-sort-default="reverse">ID<i st-sort="id"></i></th>
<th st-sort="status">Status<i st-sort="status"></i></th>
<th st-sort="name">Name<i st-sort="name"></i></th>
Thanks @stanleyxu2005 for your response. So, how did you add a symbol for the default state? I didn't see it in your code.
@lvarayut No I dont have a default state. I think using a symbol for default state looks ugly. If you notice the <i> after column text, I'd suggest you write style like .st-unsorted i {background-image:url(path/to/unsorted.png).
I solved this by adding class="sortable" to all table headers which are sortable, and then adding sorting-arrows with the following styling:
.sortable {
cursor: pointer;
}
.sortable:after {
content: url(data:image/gif;base64,R0lGODlhCwALAJEAAAAAAP///xUVFf///yH5BAEAAAMALAAAAAALAAsAAAIUnC2nKLnT4or00PvyrQwrPzUZshQAOw==);
padding-left: 1em;
}
.st-sort-ascent:after {
content: '\25B2';
}
.st-sort-descent:after {
content: '\25BC';
}
@markusberg Thanks for the technique. Inline css image is a very smart solution for me. Skill learned.
@markusberg Thanks times two! I adapted the approach to use Font Awesome icons.
.sortable {
cursor: pointer;
}
.sortable:after {
font-family: FontAwesome;
content: "\f0dc";
}
.st-sort-ascent:after {
font-family: FontAwesome;
content: "\f0de";
}
.st-sort-ascent:after {
font-family: FontAwesome;
content: "\f0dd";
}
I managed to fix the default sort icon with the following code:
th:not(.st-sort-ascent):not(.st-sort-descent):after {
font-family: FontAwesome;
content: '\f0dc';
}
It shows a default icon if the th cells don't have a sorting class applied.
@ConradPilloud I do apologize for compounding reply on reply but i believe for f0dd the class should be ..st-sort-descent then again, maybe not, but the following worked for me
.sortable {
cursor: pointer;
}
.sortable:after {
font-family: FontAwesome;
content: "\f0dc";
}
.st-sort-ascent:after {
font-family: FontAwesome;
content: "\f0de";
}
.st-sort-descent:after {
font-family: FontAwesome;
content: "\f0dd";
}
Great stuff AllenBW and Laurent R... I used sortable CSS and working fine.
Regards, Elan
altough similar, I've did it a little bit differently:
<th st-sort="Data">Data <span id="sort" class="glyphicon"></span></th>
<th st-sort="Unidade">Unidade <span id="sort" class="glyphicon"></span></th>
(notice the span)
CSS:
th[st-sort]:not(.st-sort-ascent):not(.st-sort-descent) span#sort.glyphicon:after{
content: "\e150";
color: #DDD
}
th.st-sort-ascent span#sort.glyphicon:after{
content: "\e155";
color: #337ab7
}
th.st-sort-descent span#sort.glyphicon:after{
content: "\e156";
color: #b77a33
}
Ie, use [st-sort], without the need of .sortable. I find the span a good way to manage more complex headers and where should the icon go. And a little color to make it prettier..
Please try this,
` [data-st-sort] { background-position: right; background-repeat: no-repeat; padding-right: 30px; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAQAAADYWf5HAAAAkElEQVQoz7X QMQ5AQBCF4dWQSJxC5wwax1Cq1e7BAdxD5SL+Tq/QCM1oNiJidwox0355mXnG/DrEtIQ6azioNZQxI0ykPhTQIwhCR+BmBYtlK7kLJYwWCcJA9M4qdrZrd8pPjZWPtOqdRQy320YSV17OatFC4euts6z39GYMKRPCTKY9UnPQ6P+GtMRfGtPnBCiqhAeJPmkqAAAAAElFTkSuQmCC'); }
.st-sort-ascent { background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAByUDbMAAAAZ0lEQVQ4y2NgGLKgquEuFxBPAGI2ahhWCsS/gDibUoO0gPgxEP8H4ttArEyuQYxAPBdqEAxPBImTY5gjEL9DM+wTENuQahAvEO9DMwiGdwAxOymGJQLxTyD+jgWDxCMZRsEoGAVoAADeemwtPcZI2wAAAABJRU5ErkJggg=='); }
.st-sort-descent { background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAByUDbMAAAAZUlEQVQ4y2NgGAWjYBSggaqGu5FA/BOIv2PBIPFEUgxjB+IdQPwfC94HxLykus4GiD+hGfQOiB3J8SojEE9EM2wuSJzcsFMG4ttQgx4DsRalkZENxL+AuJQaMcsGxBOAmGvopk8AVz1sLZgg0bsAAAAASUVORK5CYII= '); }`
Came here for same issue. Best thanks for solution ^