Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. $("table#aspect_statistics_StatisticsTransformer_table_list-table").each(function () {
  2. var legacy = false;
  3. //Si existen valores legados
  4. if ($(this).find("tr:contains('legacy')").length) {
  5. legacy = true;
  6. //Para cada fila legacy
  7. $(this).find("tr:contains('legacy')").each(function () {
  8. var name_legacy = $(this).find("td:nth-child(1)").text();
  9. var val_legacy = parseInt($(this).find("td:nth-child(2)").text());
  10. var finded = false;
  11. $(this).prevAll().each(function () {
  12. if (name_legacy === $(this).find("td:nth-child(1)").text() + "(legacy)") {
  13. $(this).find("td:nth-child(2)").text(val_legacy + parseInt($(this).find("td:nth-child(2)").text()));
  14. finded = true;
  15. }
  16. });
  17. $(this).nextAll().each(function () {
  18. if (name_legacy === $(this).find("td:nth-child(1)").text() + "(legacy)") {
  19. $(this).find("td:nth-child(2)").text(val_legacy + parseInt($(this).find("td:nth-child(2)").text()));
  20. finded = true;
  21. }
  22. });
  23. if (finded) {
  24. $(this).remove();
  25. } else {
  26. $(this).find("td:nth-child(1)").text(name_legacy.replace("(legacy)", ""));
  27. }
  28. });
  29. }
  30. if (legacy) {
  31. //Ordena y da estilo a la tabla si hay valores legados
  32. sortTable($(this));
  33. styleTable($(this));
  34. }
  35. });
  36.  
  37. //Ordena las tablas de estadísticas de uso de los items
  38. function sortTable(table) {
  39. var tbody = table.find('tbody');
  40. tbody.find('tr').sort(function (a, b) {
  41. return parseInt($('td:last', b).text()) - parseInt($('td:last', a).text());
  42. }).appendTo(tbody);
  43. }
  44.  
  45. //Añade estilo a las tablas de estadísticas de uso de los items
  46. function styleTable(table) {
  47. var tbody = table.find('tbody');
  48. tbody.find('tr').each(function (index) {
  49. if ((index + 1) % 2 === 0) {
  50. $(this).removeClass('even odd').addClass('even');
  51. } else {
  52. $(this).removeClass('even odd').addClass('odd');
  53. }
  54. });
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement