Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

nat sort tr in 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)
        }
    })







Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery select option value id no not exists 
Javascript :: react load different .env for local, dev, and prod 
Javascript :: delete slash commands discord.js 
Javascript :: At line:1 char:1 + nodemon server.js 
Javascript :: react native expo release apk 
Javascript :: generate random date in a range 
Javascript :: how to can i get custom data attribute value in javascript 
Javascript :: image url to file js 
Javascript :: node express js set server timeout 
Javascript :: graphql disable cache 
Javascript :: add firebase angular 
Javascript :: sequelize custom primary key 
Javascript :: update all dependencies npm 
Javascript :: slice eliminar el ultimo caracter 
Javascript :: how can auto download window print in javascript 
Javascript :: jquery call dynamically created class 
Javascript :: express serve static files 
Javascript :: fetch url in javascript 
Javascript :: close bootstrap modal with javascript 
Javascript :: javascript find document body 
Javascript :: cloudinary download url 
Javascript :: javascript read xlsx file 
Javascript :: javascript hasclass 
Javascript :: javascript random alphabet 
Javascript :: string to kebab case 
Javascript :: split words in javascript 
Javascript :: javascript get bit 
Javascript :: node_env is not an internal or external command error 
Javascript :: js check query string 
Javascript :: open google chrome in puppeteer macos 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =