Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var sorterID = function(x,y)
- {
- var ans = x.ProductID-y.ProductID;
- return ans;
- if(ans > 0){
- ans = 1
- }
- if (ans < 1)
- {
- ans = -1
- }
- else{
- ans = 0;
- }
- return ans
- }
- var sorterIDDesc = function(x,y)
- {
- var ans = y.ProductID-x.ProductID;
- return ans;
- if(ans > 0){
- ans = -1
- }
- if (ans < 1)
- {
- ans = 1
- }
- else{
- ans = 0;
- }
- return ans
- }
- var sorterPrice = function(x,y)
- {
- var ans = x.UnitPrice-y.UnitPrice;
- return ans;
- if(ans > 0){
- ans = 1
- }
- if (ans < 1)
- {
- ans = -1
- }
- else{
- ans = 0;
- }
- return ans
- }
- var sorterPriceDesc = function(x,y)
- {
- var ans = y.unitPrice -x.UnitPrice;
- return ans;
- if(ans > 0){
- ans = -1
- }
- if (ans < 1)
- {
- ans = 1
- }
- else{
- ans = 0;
- }
- return ans
- }
- function sortName(x,y){
- if (x.productName < y.productName){
- return 0;
- }
- else if (x.productName > y.productName)
- {
- return -1;
- }
- else{
- return 0;
- }
- }
- function sortNameDesc(x,y){
- if (x.productName < y.productName){
- return -1;
- }
- else if (x.productName > y.productName)
- {
- return 1;
- }
- else{
- return 0;
- }
- }
- var coolHot = function(){
- var trTags = document.getElementsByTagName("tr");
- var i = 0;
- while(i < trTags.length){
- if(i % 2 == 0){
- trTags[i].className = "cool";
- }else{
- trTags[i].className = "hot";
- }
- i++;
- }
- }
- var stringFunc = function(){
- var desc = "";
- desc = desc+ "<tr>";
- desc = desc + "<td>" + this.ProductID + "</td>";
- desc = desc + "<td>" + this.ProductName + "</td>";
- desc = desc + "<td>" + this.UnitPrice + "</td>";
- desc = desc + "</tr>";
- return desc;
- }
- function Product(aProductID, aProductName, anUnitPrice){
- this.ProductID = aProductID;
- this.ProductName = aProductName;
- this.UnitPrice = anUnitPrice;
- this.toString = stringFunc;
- }
- var destroyChild = function(){
- var myNode = document.getElementById("message");
- while (myNode.firstChild) {
- myNode.removeChild(myNode.firstChild);
- }
- }
- var createTable = function()
- {
- var myNode = document.getElementById("message");
- while (myNode.firstChild) {
- myNode.removeChild(myNode.firstChild);
- }
- }
- var message = document.getElementById("message");
- var aListOfProducts = [];
- aListOfProducts[1] = new Product(1, "Chai", 18);
- aListOfProducts[2] = new Product(2, "Chang", 19);
- aListOfProducts[3] = new Product(3, "Aniseed Syrup", 10);
- aListOfProducts[4] = new Product(4, "Chef Anton's Cajun Seasoning", 22);
- aListOfProducts[5] = new Product(5, "Chef Anton's Gumbo Mix", 21.35);
- aListOfProducts[6] = new Product(6, "Grandma's Boysenberry Spread", 25);
- aListOfProducts[7] = new Product(7, "Uncle Bob's Organic Dried Pears", 30);
- aListOfProducts[8] = new Product(8, "Northwoods Cranberry Sauce", 40);
- aListOfProducts[9] = new Product(9, "Mishi Kobe Niku", 97);
- aListOfProducts[10] = new Product(10, "Ikura", 31);
- aListOfProducts[11] = new Product(11, "Queso Cabrales", 21);
- aListOfProducts[12] = new Product(12, "Queso Manchego La Pastora", 38);
- aListOfProducts[13] = new Product(13, "Konbu", 6);
- aListOfProducts[14] = new Product(14, "Tofu", 23.25);
- aListOfProducts[15] = new Product(15, "Genen Shouyu", 15.5);
- aListOfProducts[16] = new Product(16, "Pavlova", 17.45);
- aListOfProducts[17] = new Product(17, "Alice Mutton", 39);
- aListOfProducts[18] = new Product(18, "Carnarvon Tigers", 62.5);
- aListOfProducts[19] = new Product(19, "Teatime Chocolate Biscuits", 9.2);
- aListOfProducts[20] = new Product(20, "Sir Rodney's Marmalade", 81);
- aListOfProducts[21] = new Product(21, "Sir Rodney's Scones", 10);
- aListOfProducts[22] = new Product(22, "Gustaf's Knäckebröd", 21);
- aListOfProducts[23] = new Product(23, "Tunnbröd", 9);
- aListOfProducts[24] = new Product(24, "Guaraná Fantástica", 4.5);
- aListOfProducts[25] = new Product(25, "NuNuCa Nuß-Nougat-Creme", 14);
- aListOfProducts[26] = new Product(26, "Gumbär Gummibärchen", 31.23);
- aListOfProducts[27] = new Product(27, "Schoggi Schokolade", 43.9);
- aListOfProducts[28] = new Product(28, "Rössle Sauerkraut", 45.6);
- aListOfProducts[29] = new Product(29, "Thüringer Rostbratwurst", 123.79);
- aListOfProducts[30] = new Product(30, "Nord-Ost Matjeshering", 25.89);
- aListOfProducts[31] = new Product(31, "Gorgonzola Telino", 12.5);
- aListOfProducts[32] = new Product(32, "Mascarpone Fabioli", 32);
- aListOfProducts[33] = new Product(33, "Geitost", 2.5);
- aListOfProducts[34] = new Product(34, "Sasquatch Ale", 14);
- aListOfProducts[35] = new Product(35, "Steeleye Stout", 18);
- aListOfProducts[36] = new Product(36, "Inlagd Sill", 19);
- aListOfProducts[37] = new Product(37, "Gravad lax", 26);
- aListOfProducts[38] = new Product(38, "Côte de Blaye", 263.5);
- aListOfProducts[39] = new Product(39, "Chartreuse verte", 18);
- aListOfProducts[40] = new Product(40, "Boston Crab Meat", 18.4);
- aListOfProducts[41] = new Product(41, "Jack's New England Clam Chowder", 9.65);
- aListOfProducts[42] = new Product(42, "Singaporean Hokkien Fried Mee", 14);
- aListOfProducts[43] = new Product(43, "Ipoh Coffee", 46);
- aListOfProducts[44] = new Product(44, "Gula Malacca", 19.45);
- aListOfProducts[45] = new Product(45, "Røgede sild", 9.5);
- aListOfProducts[46] = new Product(46, "Spegesild", 12);
- aListOfProducts[47] = new Product(47, "Zaanse koeken", 9.5);
- aListOfProducts[48] = new Product(48, "Chocolade", 12.75);
- aListOfProducts[49] = new Product(49, "Maxilaku", 20);
- aListOfProducts[50] = new Product(50, "Valkoinen suklaa", 16.25);
- aListOfProducts[51] = new Product(51, "Manjimup Dried Apples", 53);
- aListOfProducts[52] = new Product(52, "Filo Mix", 7);
- aListOfProducts[53] = new Product(53, "Perth Pasties", 32.8);
- aListOfProducts[54] = new Product(54, "Tourtière", 7.45);
- aListOfProducts[55] = new Product(55, "Pâté chinois", 24);
- aListOfProducts[56] = new Product(56, "Gnocchi di nonna Alice", 38);
- aListOfProducts[57] = new Product(57, "Ravioli Angelo", 19.5);
- aListOfProducts[58] = new Product(58, "Escargots de Bourgogne", 13.25);
- aListOfProducts[59] = new Product(59, "Raclette Courdavault", 55);
- aListOfProducts[60] = new Product(60, "Camembert Pierrot", 34);
- aListOfProducts[61] = new Product(61, "Sirop d'érable", 28.5);
- aListOfProducts[62] = new Product(62, "Tarte au sucre", 49.3);
- aListOfProducts[63] = new Product(63, "Vegie-spread", 43.9);
- aListOfProducts[64] = new Product(64, "Wimmers gute Semmelknödel", 33.25);
- aListOfProducts[65] = new Product(65, "Louisiana Fiery Hot Pepper Sauce", 21.05);
- aListOfProducts[66] = new Product(66, "Louisiana Hot Spiced Okra", 17);
- aListOfProducts[67] = new Product(67, "Laughing Lumberjack Lager", 14);
- aListOfProducts[68] = new Product(68, "Scottish Longbreads", 12.5);
- aListOfProducts[69] = new Product(69, "Gudbrandsdalsost", 36);
- aListOfProducts[70] = new Product(70, "Outback Lager", 15);
- aListOfProducts[71] = new Product(71, "Fløtemysost", 21.5);
- aListOfProducts[72] = new Product(72, "Mozzarella di Giovanni", 34.8);
- aListOfProducts[73] = new Product(73, "Röd Kaviar", 15);
- aListOfProducts[74] = new Product(74, "Longlife Tofu", 10);
- aListOfProducts[75] = new Product(75, "Rhönbräu Klosterbier", 7.75);
- aListOfProducts[76] = new Product(76, "Lakkalikööri", 18);
- aListOfProducts[77] = new Product(77, "Original Frankfurter grüne Soße", 13);
- //message.innerHTML = aListOfProducts.toString();
- message.innerHTML = aListOfProducts;
- var sortID = document.getElementById("sortID");
- sortID.addEventListener('click', function(){destroyChild();
- message.innerHTML = aListOfProducts.sort(sorterID)});
- var sortIDdesc = document.getElementById("sortIDdesc");
- sortIDdesc.addEventListener('click', function(){destroyChild();
- message.innerHTML = aListOfProducts.sort(sorterIDDesc)});
- var sortName = document.getElementById("sortName");
- sortName.addEventListener('click', function(){destroyChild();
- message.innerHTML = aListOfProducts.sort(sortName)});
- var sortNamedesc = document.getElementById("sortNamedesc");
- sortNamedesc.addEventListener('click', function(){destroyChild();
- message.innerHTML = aListOfProducts.sort(sortNameDesc)});
- var sortPrice = document.getElementById("sortPrice");
- sortPrice.addEventListener('click', function(){destroyChild();
- message.innerHTML = aListOfProducts.sort(sorterPrice)});
- var sortPricedesc = document.getElementById("sortPricedesc");
- sortPricedesc.addEventListener('click', function(){destroyChild();
- message.innerHTML = aListOfProducts.sort(sorterPriceDesc)});
- var trTags = document.getElementsByTagName("tr");
- var i = 0;
- while(i < trTags.length){
- if(i % 2 == 0){
- trTags[i].className = "cool";
- }else{
- trTags[i].className = "hot";
- }
- i++;
- }
Advertisement
Add Comment
Please, Sign In to add comment