Ordenamiento en JS
This commit is contained in:
@@ -401,8 +401,359 @@ setswitch = function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
function adssigscrollJSLoad() {
|
||||
|
||||
$('table.adssigscrollJS:not(.adssigscroll)').each(function () {
|
||||
try {
|
||||
let Tthis = $(this);
|
||||
let Tid = Tthis.attr('id');
|
||||
let rowVisibles = isNaN(Number(Tthis.data('rows'))) ? 1 : Number(Tthis.data('rows'));
|
||||
let colVisibles = isNaN(Number(Tthis.data('cols'))) ? 0 : Number(Tthis.data('cols'));
|
||||
let divcontainer = $(`<div id="container${Tid}" class="divContainerads"></div>`);
|
||||
let jsrows;
|
||||
let jscols;
|
||||
let stylosrow = '';
|
||||
Tthis.addClass('adssigscroll');
|
||||
|
||||
|
||||
if (rowVisibles > 0) {
|
||||
jsrows = $(`table#${Tid}.adssigscroll tr:nth-child(-n+${rowVisibles})`);
|
||||
if (jsrows) {
|
||||
jsrows.addClass('stickyRow');
|
||||
}
|
||||
if (rowVisibles > 1) {
|
||||
let numberitem = 1;
|
||||
let top = -1;
|
||||
jsrows.each(function () {
|
||||
let Trowthis = $(this);
|
||||
stylosrow = `${stylosrow}
|
||||
table#${Tid}.adssigscroll tr:nth-child(${numberitem}) { top: ${top}px; }`;
|
||||
top = top + Trowthis.outerHeight(true);
|
||||
numberitem = numberitem + 1;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (colVisibles > 0) {
|
||||
stylosrow = `${stylosrow}
|
||||
table#${Tid}.adssigscroll tr td:nth-child(-n+${colVisibles}),table#${Tid}.adssigscroll tr th:nth-child(-n+${colVisibles}) {
|
||||
position: sticky;
|
||||
left: 0;
|
||||
z-index: 3;
|
||||
}
|
||||
table#${Tid}.adssigscroll tr td:nth-child(-n+${colVisibles}) {
|
||||
background-color: inherit;
|
||||
}`;
|
||||
if (colVisibles > 1 && $(`table#${Tid}.adssigscroll tr:nth-last-child(1)`)) {
|
||||
let left = 0;
|
||||
for (let i = 1; i <= colVisibles; i++) {
|
||||
|
||||
stylosrow = `${stylosrow}
|
||||
table#${Tid}.adssigscroll tr td:nth-child(${i}),table#${Tid}.adssigscroll tr th:nth-child(${i}) {
|
||||
left: ${left}px;
|
||||
}`;
|
||||
let item = $(`table#${Tid}.adssigscroll tr:nth-last-child(1) > *:nth-child(${i})`);
|
||||
if (item) {
|
||||
left = left + item.outerWidth(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
if (rowVisibles > 0 && colVisibles > 0) {
|
||||
stylosrow = `${stylosrow}
|
||||
table#${Tid}.adssigscroll tr.stickyRow th:nth-child(-n+${colVisibles}),table#${Tid}.adssigscroll tr.stickyRow td:nth-child(-n+${colVisibles}) { z-index: 5; }`;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Tthis.before($(stylosrow = `<style>${stylosrow}</style>`));
|
||||
Tthis.before(divcontainer);
|
||||
divcontainer.append(Tthis);
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
console.log("adssigscrollJS Error:" + err.message);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
function LoadSortSticky() {
|
||||
$('body').on('click', 'table.adssigscroll tr.tr_order:not(.tsorterblock) > th ,table.adssigscroll tr.tr_order:not(.tsorterblock) > td ', function (e) {
|
||||
var tthis = $(this);
|
||||
if (tthis.closest('.NoClick').length == 0 && !($(e.target).is('a,input'))) {
|
||||
|
||||
Metronic.blockUI({ animate: true });
|
||||
var index = tthis.index();
|
||||
var multiplicador = -1;
|
||||
var tipodato = tthis.data('tipodato');
|
||||
var table = $(tthis.closest('.table')[0]);
|
||||
var tabletr = table.find('> tr:not(.stickyRow),> tbody > tr:not(.stickyRow),> thead > tr:not(.stickyRow)');
|
||||
|
||||
|
||||
if (1 == 1) {
|
||||
|
||||
if (tabletr.length > 0) {
|
||||
|
||||
el = $(tabletr[0]);
|
||||
var tdtexto = el.find("> td");
|
||||
texto = $(tdtexto[index]).data('order');
|
||||
if (texto) {
|
||||
tipodato = 'dataorder';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//console.log({ tipodato })
|
||||
tthis.closest('tr').addClass('tsorterblock');
|
||||
setTimeout(
|
||||
function () {
|
||||
if (tthis.hasClass('desc')) {
|
||||
tthis.closest('tr').find('th').removeClass('asce');
|
||||
tthis.closest('tr').find('th').removeClass('desc');
|
||||
tthis.addClass('asce');
|
||||
}
|
||||
else {
|
||||
tthis.closest('tr').find('th').removeClass('asce');
|
||||
tthis.closest('tr').find('th').removeClass('desc');
|
||||
tthis.addClass('desc');
|
||||
multiplicador = 1;
|
||||
}
|
||||
|
||||
function reordenaruno() {
|
||||
var re = new RegExp(",", 'g');
|
||||
tipostring = 0;
|
||||
tiponumeric = 0;
|
||||
tipodate = 0;
|
||||
var mapped = tabletr.map(function (i, el) {
|
||||
el = $(el);
|
||||
var texto = el.find("> td");
|
||||
var textod = null;
|
||||
var texton = 0;
|
||||
|
||||
if (texto && texto.length > index) {
|
||||
texto = $(texto[index]).text();
|
||||
texto = texto.toLowerCase().trim();
|
||||
if (texto.length > 0) {
|
||||
var vnum = texto.replace("$", "").replace("%", "").replace("-", "").replace("(", "").replace(")", "").replace(re, "").trim();
|
||||
if (vnum.length > 0) {
|
||||
if ($.isNumeric(vnum)) {
|
||||
texton = Number(vnum);
|
||||
tiponumeric = 1;
|
||||
} else {
|
||||
var splited = texto.split("-")
|
||||
if (splited.length == 3) {
|
||||
var d = new Date(splited[2] + "-" + splited[1] + "-" + splited[0])
|
||||
if (!(d.toString == "Invalid Date")) {
|
||||
textod = d;
|
||||
tipodate = 1;
|
||||
}
|
||||
} else {
|
||||
var splited = texto.split("/")
|
||||
if (splited.length == 3) {
|
||||
var d = new Date(splited[2] + "/" + splited[1] + "/" + splited[0])
|
||||
if (!(d.toString == "Invalid Date")) {
|
||||
textod = d;
|
||||
tipodate = 1;
|
||||
}
|
||||
} else {
|
||||
tipostring = 1
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
texto = null;
|
||||
}
|
||||
} else {
|
||||
texto = null;
|
||||
}
|
||||
} else {
|
||||
texto = null;
|
||||
}
|
||||
return { index: i, value: texto, valued: textod, valuen: texton, obj: el };
|
||||
});
|
||||
if (tipostring == 1) {
|
||||
mapped.sort(function (a, b) {
|
||||
return (+(a.value > b.value) || +(a.value === b.value) - 1) * multiplicador;
|
||||
});
|
||||
//tthis.closest('tr').find('th').data('tipodato', 'string')
|
||||
} else {
|
||||
if (tipodate == 1) {
|
||||
mapped.sort(function (a, b) {
|
||||
return (+(a.valued > b.valued) || +(a.valued === b.valued) - 1) * multiplicador;
|
||||
});
|
||||
//tthis.closest('tr').find('th').data('tipodato', 'date')
|
||||
} else {
|
||||
mapped.sort(function (a, b) {
|
||||
return (+(a.valuen > b.valuen) || +(a.valuen === b.valuen) - 1) * multiplicador;
|
||||
});
|
||||
//tthis.closest('tr').find('th').data('tipodato', 'numeric')
|
||||
}
|
||||
}
|
||||
mapped.each(function (i, el) {
|
||||
table.append(this.obj);
|
||||
});
|
||||
}
|
||||
function reordenardos() {
|
||||
var re = new RegExp(",", 'g');
|
||||
tipostring = 0;
|
||||
tiponumeric = 0;
|
||||
tipodate = 0;
|
||||
var mapped = tabletr.map(function (i, el) {
|
||||
el = $(el);
|
||||
var tdtexto = el.find("> td");
|
||||
var texto = null;
|
||||
if (tdtexto && tdtexto.length > index) {
|
||||
texto = $(tdtexto[index]).text();
|
||||
texto = texto.toLowerCase().trim();
|
||||
} else {
|
||||
texto = null;
|
||||
}
|
||||
return { index: i, value: texto, obj: el };
|
||||
});
|
||||
|
||||
mapped.sort(function (a, b) {
|
||||
return (+(a.value > b.value) || +(a.value === b.value) - 1) * multiplicador;
|
||||
});
|
||||
mapped.each(function (i, el) {
|
||||
table.append(this.obj);
|
||||
});
|
||||
}
|
||||
function reordenartres() {
|
||||
var re = new RegExp(",", 'g');
|
||||
tipostring = 0;
|
||||
tiponumeric = 0;
|
||||
tipodate = 0;
|
||||
var mapped = tabletr.map(function (i, el) {
|
||||
el = $(el);
|
||||
var tdtexto = el.find("> td");
|
||||
var texto = null;
|
||||
var textod = null;
|
||||
if (tdtexto && tdtexto.length > index) {
|
||||
texto = $(tdtexto[index]).text();
|
||||
texto = texto.toLowerCase().trim();
|
||||
var splited = texto.split("-")
|
||||
if (splited.length == 3) {
|
||||
var d = new Date(splited[2] + "-" + splited[1] + "-" + splited[0])
|
||||
if (!(d.toString == "Invalid Date")) {
|
||||
textod = d;
|
||||
}
|
||||
} else {
|
||||
var splited = texto.split("/")
|
||||
if (splited.length == 3) {
|
||||
var d = new Date(splited[2] + "/" + splited[1] + "/" + splited[0])
|
||||
if (!(d.toString == "Invalid Date")) {
|
||||
textod = d;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
texto = null;
|
||||
}
|
||||
return { index: i, value: textod, obj: el };
|
||||
});
|
||||
|
||||
mapped.sort(function (a, b) {
|
||||
return (+(a.value > b.value) || +(a.value === b.value) - 1) * multiplicador;
|
||||
});
|
||||
mapped.each(function (i, el) {
|
||||
table.append(this.obj);
|
||||
});
|
||||
}
|
||||
function reordenarcuatro() {
|
||||
var re = new RegExp(",", 'g');
|
||||
tipostring = 0;
|
||||
tiponumeric = 0;
|
||||
tipodate = 0;
|
||||
var mapped = tabletr.map(function (i, el) {
|
||||
el = $(el);
|
||||
var tdtexto = el.find("> td");
|
||||
var texto = null;
|
||||
var texton = 0;
|
||||
if (tdtexto && tdtexto.length > index) {
|
||||
texto = $(tdtexto[index]).text();
|
||||
texto = texto.toLowerCase().trim();
|
||||
|
||||
if (texto.length > 0) {
|
||||
var vnum = texto.replace("$", "").replace("%", "").replace("-", "").replace("(", "").replace(")", "").replace(re, "").trim();
|
||||
if (vnum.length > 0) {
|
||||
if ($.isNumeric(vnum)) {
|
||||
texton = Number(vnum);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
texto = null;
|
||||
}
|
||||
return { index: i, value: texton, obj: el };
|
||||
});
|
||||
|
||||
mapped.sort(function (a, b) {
|
||||
return (+(a.value > b.value) || +(a.value === b.value) - 1) * multiplicador;
|
||||
});
|
||||
mapped.each(function (i, el) {
|
||||
table.append(this.obj);
|
||||
});
|
||||
}
|
||||
|
||||
function reordenarcinco() {
|
||||
var re = new RegExp(",", 'g');
|
||||
tipostring = 0;
|
||||
tiponumeric = 0;
|
||||
tipodate = 0;
|
||||
var mapped = tabletr.map(function (i, el) {
|
||||
el = $(el);
|
||||
var tdtexto = el.find("> td");
|
||||
var texto = null;
|
||||
var texton = 0;
|
||||
if (tdtexto && tdtexto.length > index) {
|
||||
texton = Number($(tdtexto[index]).data('order'));
|
||||
|
||||
} else {
|
||||
texto = null;
|
||||
}
|
||||
return { index: i, value: texton, obj: el };
|
||||
});
|
||||
//console.log(mapped)
|
||||
mapped.sort(function (a, b) {
|
||||
return (+(a.value > b.value) || +(a.value === b.value) - 1) * multiplicador;
|
||||
});
|
||||
mapped.each(function (i, el) {
|
||||
table.append(this.obj);
|
||||
});
|
||||
}
|
||||
switch (tipodato) {
|
||||
case 'string':
|
||||
reordenardos();
|
||||
break;
|
||||
case 'date':
|
||||
reordenartres();
|
||||
break;
|
||||
case 'numeric':
|
||||
reordenarcuatro();
|
||||
break;
|
||||
case 'dataorder':
|
||||
reordenarcinco();
|
||||
break;
|
||||
default:
|
||||
reordenaruno();
|
||||
}
|
||||
|
||||
tthis.closest('tr').removeClass('tsorterblock');
|
||||
Metronic.unblockUI();
|
||||
}, 100);
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
function ADScroller2() {
|
||||
adssigscrollJSLoad();
|
||||
$('table.ADSCROLLER2').each(function () {
|
||||
try {
|
||||
var Tthis = $(this);
|
||||
@@ -1659,7 +2010,7 @@ function ADSReady() {
|
||||
|
||||
}
|
||||
function loadsortadscroll() {
|
||||
|
||||
LoadSortSticky();
|
||||
$('body').on('click', '.ADScroller > div > table > tbody > tr.tsorter:not(.tsorterblock) >th ,.ADScroller > div > table > thead > tr.tsorter:not(.tsorterblock) >th ', function (e) {
|
||||
var tthis = $(this);
|
||||
if (tthis.closest('.NoClick').length == 0 && !($(e.target).is('a,input'))) {
|
||||
|
||||
Reference in New Issue
Block a user