I am trying to use this script to sort the html table: http://www.kryogenix.org/code/browser/sorttable/
JS code itself: http://www.kryogenix.org/code/browser/sorttable/sorttable.js
I used the customkey option and it works when I click the heading. I would like to auto sort based on that customkey when the page loads. How can I do that? I want to use this specific script. I tried window.onload but with no luck.
After loading the page just trigger a click on the header column you want to sort. Try with following
javascriptcode. I assume that there is only one table in the page. Perhaps you will need to be more specific usinggetElementsByTagNameor withgetElementByIdinstead. The[1]is the column number. You don’t need to attach a click handler before that because that task is done by the code ofsorttable.js.