Javascript Sort Table Columns
3 Attachment(s)
On our Intranet at work I look after a web app that uses a simple html table to display results - nothing complicated, data is retrieved from a SQL database with a simple select statement.
I want to add sorting capability to the table and I have a nice simple Javascript that does it nicely all bar one point - I would like to add an arrow to indicate the sort order. I also have a complicated Javascript that does add a direction of sort indicator, so i thought I could just lift that bit of code and add into the simple Javascript, but it's beyond me - maybe someone can help - much appreciated. Here's the simple javascript and html thatworks nicely: Code:
<!DOCTYPE html> Code:
sheet.insertRule('table.js-sort-asc thead tr > .js-sort-active:not(.js-sort-none):after {content: "\\25b2";font-size: 0.7em;padding-left: 3px;line-height: 0.7em;}', 0); I've also attached three screenshots of the desired effect I'm after. Thanks guys and gals - hope someone can help |
I guess it would be redundant to suggest the clip you added inserts a rule into a style sheet. The unicode in the content field is for up arrow (25b2) and down arrow (25bc) , however there isn't a style sheet included in the code you posted and the rule will need application the element you wish to apply it to.
This link might help with your next step: https://developer.mozilla.org/en-US/...eet/insertRule |
Quote:
Code:
<!DOCTYPE html> It looks like it has a dynamic style, I'm sure it should be possible to 'lift' this code and drop itinto the simpler script? |
I wouldn't call it long. It does what you want so the answer is to understand what you need to do to use it so if you're not a programmer you may have a challenge if you need to modify it. On the other hand if you just want to use it in some page you just need to understand the format it expects from the table.
It looks for a table with the class "js-sort-table" and when a column header is clicked it adds an arrow showing the sort directing. Click it again it changes direction. It handles number, string and date comparison. I added a date column as an example but you can completely rewrite the table and it will work; Code:
<table class="js-sort-table" id="demo1" border=1 cellspacing=0> |
All times are GMT -5. The time now is 12:52 PM. |