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

  • SEARCH
  • Home
  • 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 7806153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:26:34+00:00 2026-06-02T02:26:34+00:00

EDIT 4/16/2012: I fixed the problems and have the sortings working appropriately. I also

  • 0

EDIT 4/16/2012: I fixed the problems and have the sortings working appropriately. I also have converted the timezones into their one letter UTC codes (A-Z). The only thing left is getting the formatter to check for Daylight Savings, but there’s a lot on that subject. However feel free to contribute if you want it would be most welcomed. Thank you all for helping me out in reaching the goal.

EDIT2 4/16/2012: I solved it!! Due to the date being already in UTC, I was doing some needless conversions that were creating some conflicts/weird results. This question is to be considered SOLVED. Thank you everyone who helped.

I’m using knockoutjs to create a widget (table in html/javascript) that pulls info dynamically from my server. I’m stuck on sorting methods for this. I have made and downloaded different versions of table sorting methods but they all make the initial data that is pulled from the server disappear. They treat the tables like the info can’t be edited; so there seems to be a conflict with my table as I need to make all the info be editable.

Right now in my ViewModel.js file I have:

Event(column1,column2,column3,...columnN){
    var self = this;
    self.column1 = column1;
    self.column2 = column2;
    .
    .
}

function ViewModel(){
    var self= this;
    self.rows = ko.observableArray([]);

    self.addRow = function(){
        self.rows.push("","",.......);
    }

    //THIS REMOVE FUNCTION DOESN'T WORK
    self.removeRow = function(row)
        self.rows.remove(row);
    }

    //THIS DOESN'T WORK EITHER, a.column and b.column, the 'column would be column1, 
    //column2, etc.
    self.SortMethod = function(){
        self.items.sort(function(a,b){
            return a.column < b.column ? -1 : 1;
        });
    }
}

//navigate to the server and its info
function getEvents(){
    $get.JSON("http://......", 
      function(data){
          $.each(data.d, function(i,item){handleEvent(item)})
      }
    );
}

//this populates the rows/columns in the table with the events(info) from the server
//Here, 'Model' is a new ViewModel which is declared further below
function handleEvent(item){
    var newEvent = new Event(item.Event1, item.Event2,.....);
    this.Model.rows.push(newEvent);
}

this.Model = new ViewModel();
this.getEvents();
ko.applyBindings(this.Model);

//The HTML code just makes the table, the headers and the style of the table and I then use 
//data-bind to bind the info in the server into the appropriate block in the table.  
//And yes, I do use <script src="knockout.js"> and for all other js files I have in the
//HTML file.

The HTML is basically this:

title
meta
scripts
table style
table
headers <tr><td>Column1Header</td><td>Column2Header</td>.....</tr>
table body
    Example line from table's body: <td><input data-bind = "value: column1" /><td>
    buttons (for adding a row and another button for sorting the array)

 //I think it would be better to get rid of the sorting button and make it so if you click on 
//the table headers, you'll sort the table according to that header's column's information.  

==============================================================================
EDIT2:

Got the sort error corrected, I accidently forgot to rename one of the copied sort functions so it was causing a conflict. I still haven’t been able to figure out how to get the table to return to its original order. If someone can look at the sorting function I made and show me what I need to do or change it would be greatly appreciated.

I also haven’t been able to get the remove function to work correctly. It’s causing a conflict somehow as when I include it in the table, the data from the server isn’t populating the table.

EDIT:
I managed to figure out a “quick and dirty” way to get a sorting for an individual column. It goes something like this:

//After the line: self.rows = ko.observableArray([]); I continued with:
self.sortColumn = "Column1";
self.sortAscending = true;

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

However, if I copied this code for all the other columns (changing all the Column1’s into Column2’s and 3’s and so on for each different copy of the function); some rows aren’t sorted correctly. However if I keep just this one function without any copies towards the other columns, it works fine.

**I also need the ability to return the table to its original order. Right now I have this one function binded to the Column1 header in the table. If I click once, it puts it in descending order, and if I click the header again; it puts the table in ascending order (according to Column1’s information of course). Now the problem is to make it where if I click a third time, it restores the table to its default (original) order.

  • 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-02T02:26:35+00:00Added an answer on June 2, 2026 at 2:26 am

    I solved it!! Due to the date being already in UTC, I was doing some needless conversions that were creating some conflicts/weird results. This question is to be considered SOLVED. Thank you everyone who helped.

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

Sidebar

Related Questions

EDIT : As of 2012-06-11 this bug has been finally fixed! https://bugs.webkit.org/show_bug.cgi?id=35981#c1 I have
Edit (2012-04-12): Since this question was asked it is now possible (as of jQuery
EDIT: Duplicate of Should Entity Framework Context be Put into Using Statement? I've been
I have a page of categories, when the user clicks one, the items under
Edit: Feb 7, 2012 - Turns out the key parameter disappears from the GridView
EDIT: Common.Logging 2.1.1 was released on June 9, 2012 and the Github page is
EDIT: Now a Major Motion Blog Post at http://messymatters.com/sealedbids The idea of rot13 is
EDIT: I used, finally, inotify. As stefanB says, inotify is the thing to use.
EDIT 1 I apologize but after reading the 2 suggested articles I still don't
EDIT: OK, I believe the following solutions are valid: Use the jQuery AOP plugin.

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.