Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7812689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:35:41+00:00 2026-06-02T04:35:41+00:00

UPDATE: I would also like for ascending/descending arrow keys to appear appropriately next to

  • 0

UPDATE: I would also like for ascending/descending arrow keys to appear appropriately next to the header that is clicked to show the current sorted order. I already made the images in paint and made sure they were like 12 x 10 pixels.

I have done a lot of searching and it seems that without downloading a file it can’t be done. I’d like to use the code I currently have to somehow intially have my HTML table sorted by a certain column’s values that are dynamically populated from a private server.

I am using Knockoutjs for all the data-bindings.

The sorting works fine when I click on the column’s header. It currently puts it in ascending/descending order every other click (click once: descending, click again: ascending, click again: descending……..). I want to get the table populated initially with the TimeObserved info already sorted in descending order with the code I already have (if possible). Any help is appreciated.

PLEASE NOTE: I am rather new to all this and I know from personnal experience that someone will probably ask to put it into jsfiddle. I’m not used to jsfiddle and am busy at work. Please understand that I don’t have the time right now to convert it into that kind of format and that the codes provided should be more than informative and organized to read and understand. Thank you.

Here’s the code snippets needed for this:

HTML file:

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

<table border="6" id="widget"><thead>
    <tr>
        <th><a href=#" data-bind="click: SortByTimeObserved">TimeObserved</a></th>
    </tr></thead>

    <tbody data-bind="foreach: rows">
        <td><input data-bind="value: TimeObserved" /></td>
    </tbody>
</table>

<script src="TableViewModel.js" type="text/javascript"></script>

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Heres the javascript viewmodel file:

==================================================================================

function Event(TimeObserved){
    var self = this;
    self.TimeObserved = TimeObserved;
}

function TableViewModel(){
    var self = this;
    self.sortColumn = "TimeObserved";
    self.sortAscending = true;

    self.SortByTimeObserved(){
        if(self.sortColumn == "TimeObserved")
            self.sortAscending = !self.sortAscending;
        else{
            self.sortColumn = "TimeObservable";
            self.sortAscending = true;
        }
        self.rows.sort(function(a,b){
            if(self.sortAscending == true)
                for(self.TimeObserved in self.rows)
                    return a.TimeObserved > b.TimeObserved ? -1 : 1;
             else
                 return a.TimeObserved < b.TimeObserved ? -1 : 1;
        });
    }
}

this.Model = new TableViewModel;
ko.applyBindings(this.Model);

==================================================================================

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:35:43+00:00Added an answer on June 2, 2026 at 4:35 am

    I solved it. When I use:

    function getEvents(){
        $.getJSON("http://.....",
            function (data){
                $.each(data.d, function (i, item){
                    handleEvent(item)
                });
            Model.SortByTimeObserved(); // <----This is what solved the problem
            }
        );
     }
    

    Adding the Model.SortByTimeObservable(); after I populate the handleEvent with the items from the server then orders the TimeObserved in the proper order. The this.Model.SortByTimeObserved(); at the end of the ViewModel.js file is not needed as it would only put everything in the opposite order.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to update my current SB2 theme Sunburst so that the current
I'm working on a project that is hosted on Bitbucket. I would also like
I would like to update (change the content) some part of the webpage without
I would like to update 3 rows of a single table, with different values
I would like to update an xml file from another xml file.I have used
I would like to update the Diagnostic configuration file for the azure roles whenever
I would like to update one of the variables in a vector layer class
I would like to update a number without changing its placement in the output
I would like to update some data with JSON when the user clicks on
I would like to use jquery to update my attribute value, because I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.