EDITING 4/16/2012: I fixed the problems and handled the sorts correctly. I also converted the time slots to their single-letter UTC (AZ) codes. The only thing left is to get a formatter to check Summer Savings, but there is a lot on this topic. However, feel free to contribute if you want this to be most welcome. Thanks to everyone for helping me achieve my goal.
EDIT2 4/16/2012: I decided! Due to the fact that the date is already in UTC, I did some unnecessary conversions that created some conflicts / strange results. This question should be considered SOLVED. Thanks to everyone who helped.
I use knockoutjs to create a widget (table in html / javascript) that dynamically outputs information from my server. I went in cycles on sorting methods for this. I have made and downloaded various versions of table sorting methods, but all of them make the original data that is pulled from the server disappear. They process tables as information cannot be edited; therefore, there seems to be a conflict with my table, since I need to make all the information 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("","",.......); }
==================================================== ============================= EDIT2:
If the sorting error is fixed, I accidentally forgot to rename one of the copied sorting functions to cause a conflict. I still could not figure out how to return the table to its original order. If someone can look at the sorting function that I did and show me what I need to do or change, it would be very helpful.
I also could not get the delete function to work correctly. This causes a conflict anyway, as when I include it in the table, the data from the server does not fill the table.
EDIT: I was able to figure out a “quick and dirty” way to get sorting for a single column. This happens 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 columns 1 to columns 2 and 3, etc. for every other copy of the function); some rows are not sorted correctly. However, if I save only one function without any copies in relation to other columns, it works fine.
** I also need the ability to return the table to its original order. Right now I have one function bound to the Column1 header in the table. If I click once, he will put it in descending order, and if I click the title again; he places the table in ascending order (according to the information in column 1, of course). Now the problem is to do this, if I clicked a third time, it will restore the default table (original).