nat clasifica tr en js

/******** This code was pasted by ProgrammerRimon on: 2022-02-23 *********////////

/********
Sorting elements inside parent elements
************///////////


	    // nat sort function ;;
		const func  = {
        // @param: parent element for sorting
        natSort: function(pe, el, sort) {
            var arrayList = []
            el.forEach((e, i) => {
                arrayList.push(e.getAttribute('rowid'))
            });
			if(sort === 'asc') {arrayList = arrayList.sort((a,b)=> a-b);}
			else if(sort === 'desc') {arrayList = arrayList.sort((a,b)=> b-a);}	
            arrayList.forEach(i => {
                var row = document.querySelector('#row'+i);
                pe.append(row);
            });
        },
        e:function(e) {return document.querySelector(e)},
        ea:function(e) {return document.querySelectorAll(e)},
		getA:function(e, n) {return e.getAttribute(n)},
		setA:function(e, n, v) {e.setAttribute(n, v)}
    }
    const buttonList = func.ea('.do-sort');
    buttonList.forEach((e)=>{
        e.onclick = function () {
		var sort = func.getA(this, 'sort');			
			buttonList.forEach(el => {
			if(sort === 'asc') {func.setA(el, 'sort', 'desc')} else {func.setA(el, 'sort', 'asc')}		
			});
            func.natSort(func.e('#nat-sort'), func.ea('.js-sortable-tr'), sort)
        }
    })







Homely Hamerkop