Advertisement
BigRedDoge

Untitled

Mar 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. function ListPriceSort(sortType) {
  2. var table = ($('#purchasetable').children().toArray());
  3. var tablelength = table.length;
  4. var pricing = new Promise(function(resolve, reject) {
  5. var pricearr = [];
  6. var tablelength = table.length;
  7. for (var i = 0; i < tablelength; i++) {
  8. var price = parseFloat(($($(table[i]).children()[4]).text()).replace('$', ''));
  9. pricearr.push({
  10. id: ($($(table)[i]).attr('id')),
  11. price: (price)
  12. });
  13. }
  14. console.log(pricearr);
  15. resolve (pricearr);
  16. });
  17.  
  18. pricing.then((prices) => {
  19. if (sortType === "hightolow") {
  20. var highsort = (prices).sort(function(a, b) { return b.price - a.price });
  21. var tablesort = new Promise(function(resolve, reject) {
  22. var highhtml = [];
  23. for (var x = 0; x < highsort.length; x++) {
  24. var itemhtml = "<tr id='#" + highsort[x].id + "' onclick=submitid(" +
  25. parseFloat(((highsort[x].id).replace('#', ''))) + ")>" +
  26. $($('#purchasetable').find('#' + highsort[x].id)).html() +
  27. "</tr>";
  28. highhtml.push(itemhtml);
  29. }
  30. resolve (highhtml);
  31. });
  32. tablesort.then((html) => {
  33. var sorting = new Promise(function(resolve, reject) {
  34. var sorted = html;
  35. $('#purchasetable').empty();
  36. resolve (sorted);
  37. });
  38. sorting.then((sorted) => {
  39. for (var z = 0; z < sorted.length; z++) {
  40. $('#purchasetable').append(sorted[z]);
  41. }
  42. });
  43. });
  44. } else if (sortType === "lowtohigh") {
  45. var lowsort = (prices).sort(function(a, b) { return a.price - b.price });
  46. var tablesort = new Promise(function(resolve, reject) {
  47. var lowhtml = [];
  48. for (var x = 0; x < lowsort.length; x++) {
  49. var itemhtml = "<tr id='#" + lowsort[x].id + "' onclick=submitid(" +
  50. parseFloat(((lowsort[x].id).replace('#', ''))) + ")>" +
  51. $($('#purchasetable').find('#' + lowsort[x].id)).html() +
  52. "</tr>";
  53. lowhtml.push(itemhtml);
  54. }
  55. resolve (lowhtml);
  56. });
  57. tablesort.then((html) => {
  58. var sorting = new Promise(function(resolve, reject) {
  59. var sorted = html;
  60. $('#purchasetable').empty();
  61. resolve (sorted);
  62. });
  63. sorting.then((sorted) => {
  64. for (var z = 0; z < sorted.length; z++) {
  65. $('#purchasetable').append(sorted[z]);
  66. }
  67. });
  68. });
  69. }
  70. });
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement