{"id":6568,"date":"2024-01-11T16:46:00","date_gmt":"2024-01-11T16:46:00","guid":{"rendered":"https:\/\/codehim.com\/?p=6568"},"modified":"2024-01-22T14:47:16","modified_gmt":"2024-01-22T09:47:16","slug":"javascript-sort-table-on-header-click","status":"publish","type":"post","link":"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/","title":{"rendered":"JavaScript Sort Table on Header Click"},"content":{"rendered":"<p>This JavaScript code snippet helps you to sort the HTML table on header click. It stores the table data in const objects and renders that to the HTML table dynamically. In order to sort the table columns, it uses the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Array\/sort\" target=\"_blank\" rel=\"noopener\">JavaScript array sort method<\/a>.<\/p>\n<h2>How to Create JavaScript Sort Table on Header Click<\/h2>\n<p>1. First of all, create the HTML table element with a unique id and place &#8220;th&#8221; element with the data-filter-value attribute. Similarly, define data-filter values as follows:<\/p>\n<pre class=\"prettyprint linenums lang-html\"> &lt;table id=\"squadTable\" class=\"table table-dark table-striped\"&gt;\r\n    &lt;thead&gt;\r\n        &lt;tr&gt;\r\n            &lt;th data-filter-value=\"no\" class=\"active\"&gt;No &lt;i class=\"fa fa-sort\"&gt;&lt;\/i&gt;&lt;\/th&gt;\r\n            &lt;th&gt;Ad\u0131&lt;\/th&gt;\r\n            &lt;th&gt;Pozisyonu&lt;\/th&gt;\r\n            &lt;th data-filter-value=\"dateOfBirth\"&gt;Ya\u015f &lt;i class=\"fa fa-sort\"&gt;&lt;\/i&gt;&lt;\/th&gt;\r\n            &lt;th data-filter-value=\"match\"&gt;Ma\u00e7 &lt;i class=\"fa fa-sort\"&gt;&lt;\/i&gt;&lt;\/th&gt;\r\n            &lt;th data-filter-value=\"goal\"&gt;Gol &lt;i class=\"fa fa-sort\"&gt;&lt;\/i&gt;&lt;\/th&gt;\r\n            &lt;th data-filter-value=\"assist\"&gt;AST &lt;i class=\"fa fa-sort\"&gt;&lt;\/i&gt;&lt;\/th&gt;\r\n            &lt;th data-filter-value=\"yellowCard\"&gt;SK &lt;i class=\"fa fa-sort\"&gt;&lt;\/i&gt;&lt;\/th&gt;\r\n            &lt;th data-filter-value=\"doubleYellowCard\"&gt;\u00c7SK &lt;i class=\"fa fa-sort\"&gt;&lt;\/i&gt;&lt;\/th&gt;\r\n            &lt;th data-filter-value=\"redCard\"&gt;KK &lt;i class=\"fa fa-sort\"&gt;&lt;\/i&gt;&lt;\/th&gt;\r\n        &lt;\/tr&gt;\r\n    &lt;\/thead&gt;\r\n    &lt;tbody&gt;\r\n    &lt;\/tbody&gt;\r\n&lt;\/table&gt;<\/pre>\n<p>2. After that, define the following CSS style for the table header &#8220;th&#8221; element:<\/p>\n<pre class=\"prettyprint linenums lang-css\">th[data-filter-value] {\r\n  cursor: pointer;\r\n}\r\nth.active {\r\n  color: red;\r\n}<\/pre>\n<p>3. Now, add the following JS table sort code to your project. In this code, place the table data inside the JavaScript array of objects.<\/p>\n<pre class=\"prettyprint linenums lang-js\">const data = [{\r\n  \"id\": \"1233213\",\r\n  \"no\": 17,\r\n  \"fullName\": \"Murat Do\u00c4\u0178an\",\r\n  \"position\": \"CMD\",\r\n  \"age\": 29,\r\n  \"dateOfBirth\": \"1985-08-06T00:00:00\",\r\n  \"match\": 12,\r\n  \"time\": 1080,\r\n  \"goal\": 12,\r\n  \"assist\": 4,\r\n  \"yellowCard\": 3,\r\n  \"doubleYellowCard\": 0,\r\n  \"redCard\": 2 },\r\n{\r\n  \"id\": \"41233213\",\r\n  \"no\": 58,\r\n  \"fullName\": \"Lorem Ipsum\",\r\n  \"position\": \"GK\",\r\n  \"age\": 28, \"dateOfBirth\": \"1985-08-06T00:00:00\",\r\n  \"match\": 34,\r\n  \"time\": 3400,\r\n  \"goal\": 1,\r\n  \"assist\": 17,\r\n  \"yellowCard\": 8,\r\n  \"doubleYellowCard\": 3,\r\n  \"redCard\": 5 },\r\n{\r\n  \"id\": \"51233213\",\r\n  \"no\": 18,\r\n  \"fullName\": \"Dolor Sit\",\r\n  \"position\": \"ST\",\r\n  \"age\": 33, \"dateOfBirth\": \"1985-08-06T00:00:00\",\r\n  \"match\": 5,\r\n  \"time\": 120,\r\n  \"goal\": 1,\r\n  \"assist\": 2,\r\n  \"yellowCard\": 5,\r\n  \"doubleYellowCard\": 1,\r\n  \"redCard\": 4 },\r\n{\r\n  \"id\": \"61233213\",\r\n  \"no\": 27,\r\n  \"fullName\": \"Amet Dolor\",\r\n  \"position\": \"DL\",\r\n  \"age\": 18, \"dateOfBirth\": \"1985-08-06T00:00:00\",\r\n  \"match\": 2,\r\n  \"time\": 12,\r\n  \"goal\": 0,\r\n  \"assist\": 1,\r\n  \"yellowCard\": 3,\r\n  \"doubleYellowCard\": 4,\r\n  \"redCard\": 5 }];\r\n\r\n\r\nlet currentFilter = \"\",\r\nprevFilter = \"\",\r\norderAsc = true;\r\n\r\nconst toggleOrder = () =&gt; {\r\n  if (currentFilter === prevFilter) {\r\n    orderAsc = !orderAsc;\r\n  } else {\r\n    orderAsc = true;\r\n  }\r\n};\r\n\r\nconst calcAge = birthDate =&gt; {\r\n  let bDate = new Date(birthDate),\r\n  bDateYear = bDate.getUTCFullYear(),\r\n  now = new Date().getFullYear();\r\n\r\n  return now - bDateYear;\r\n};\r\n\r\nconst sortTable = (array, sortKey) =&gt; {\r\n  return array.sort((a, b) =&gt; {\r\n    let x = a[sortKey],\r\n    y = b[sortKey];\r\n\r\n    return orderAsc ? x - y : y - x;\r\n  });\r\n};\r\n\r\nconst renderTable = tableData =&gt; {\r\n  return `${tableData.map(item =&gt; {\r\n    if (item.dateOfBirth.length &gt; 2) {\r\n      item.dateOfBirth = calcAge(item.dateOfBirth);\r\n    }\r\n    return (\r\n      `&lt;tr&gt;\r\n                        &lt;td&gt;${item.no}&lt;\/td&gt;\r\n                        &lt;td&gt;${item.fullName}&lt;\/td&gt;\r\n                        &lt;td&gt;${item.position}&lt;\/td&gt;\r\n                        &lt;td&gt;${item.dateOfBirth}&lt;\/td&gt;\r\n                        &lt;td&gt;${item.match}&lt;\/td&gt;\r\n                        &lt;td&gt;${item.goal}&lt;\/td&gt;\r\n                        &lt;td&gt;${item.assist}&lt;\/td&gt;\r\n                        &lt;td&gt;${item.yellowCard}&lt;\/td&gt;\r\n                        &lt;td&gt;${item.doubleYellowCard}&lt;\/td&gt;\r\n                        &lt;td&gt;${item.redCard}&lt;\/td&gt;\r\n                    &lt;\/tr&gt;`);\r\n\r\n  }).join('')}`;\r\n};\r\n\r\nconst appendTable = (table, destination) =&gt; {\r\n  document.querySelector(destination).innerHTML = table;\r\n};\r\n\r\nconst handleSortClick = () =&gt; {\r\n  const filters = document.querySelectorAll('#squadTable th');\r\n\r\n  Array.prototype.forEach.call(filters, filter =&gt; {\r\n    filter.addEventListener(\"click\", () =&gt; {\r\n      if (!filter.dataset.filterValue) return false;\r\n\r\n      Array.prototype.forEach.call(filters, filter =&gt; {\r\n        filter.classList.remove('active');\r\n      });\r\n      filter.classList.add('active');\r\n      currentFilter = filter.dataset.filterValue;\r\n      toggleOrder();\r\n      init();\r\n    });\r\n  });\r\n};\r\n\r\nconst init = () =&gt; {\r\n  let newTableData = sortTable(data, currentFilter),\r\n  tableOutput = renderTable(newTableData);\r\n\r\n  appendTable(tableOutput, '#squadTable tbody');\r\n\r\n  prevFilter = currentFilter;\r\n};\r\n\r\ninit();\r\nhandleSortClick();<\/pre>\n<p>That&#8217;s all! hopefully, you have successfully integrated this JavaScript sort table code snippet into your project. If you have any questions or facing any issues, feel free to comment below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This JavaScript code snippet helps you to sort the HTML table on header click. It stores the table data in&#8230;<\/p>\n","protected":false},"author":1,"featured_media":7039,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[116],"tags":[],"class_list":["post-6568","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vanilla-javascript"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>JavaScript Sort Table on Header Click &#8212; CodeHim<\/title>\n<meta name=\"description\" content=\"Here is a lightweight JavaScript code snippet to sort table on header click. You can view demo and download source code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript Sort Table on Header Click &#8212; CodeHim\" \/>\n<meta property=\"og:description\" content=\"Here is a lightweight JavaScript code snippet to sort table on header click. You can view demo and download source code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/\" \/>\n<meta property=\"og:site_name\" content=\"CodeHim\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codehimofficial\" \/>\n<meta property=\"article:published_time\" content=\"2024-01-11T16:46:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-22T09:47:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codehim.com\/wp-content\/uploads\/2022\/05\/javascript-sort-table-on-header-click_.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"959\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Asif Mughal\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@CodeHimOfficial\" \/>\n<meta name=\"twitter:site\" content=\"@CodeHimOfficial\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Asif Mughal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/\"},\"author\":{\"name\":\"Asif Mughal\",\"@id\":\"https:\/\/codehim.com\/#\/schema\/person\/cc48f1dbe072a89a62a98171b7db43ed\"},\"headline\":\"JavaScript Sort Table on Header Click\",\"datePublished\":\"2024-01-11T16:46:00+00:00\",\"dateModified\":\"2024-01-22T09:47:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/\"},\"wordCount\":153,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/codehim.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/codehim.com\/wp-content\/uploads\/2022\/05\/javascript-sort-table-on-header-click_.png\",\"articleSection\":[\"Vanilla JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/\",\"url\":\"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/\",\"name\":\"JavaScript Sort Table on Header Click &#8212; CodeHim\",\"isPartOf\":{\"@id\":\"https:\/\/codehim.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/codehim.com\/wp-content\/uploads\/2022\/05\/javascript-sort-table-on-header-click_.png\",\"datePublished\":\"2024-01-11T16:46:00+00:00\",\"dateModified\":\"2024-01-22T09:47:16+00:00\",\"description\":\"Here is a lightweight JavaScript code snippet to sort table on header click. You can view demo and download source code.\",\"breadcrumb\":{\"@id\":\"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/#primaryimage\",\"url\":\"https:\/\/codehim.com\/wp-content\/uploads\/2022\/05\/javascript-sort-table-on-header-click_.png\",\"contentUrl\":\"https:\/\/codehim.com\/wp-content\/uploads\/2022\/05\/javascript-sort-table-on-header-click_.png\",\"width\":1280,\"height\":959,\"caption\":\"JavaScript Sort Table on Header Click\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/codehim.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Vanilla JavaScript\",\"item\":\"https:\/\/codehim.com\/category\/vanilla-javascript\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"JavaScript Sort Table on Header Click\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/codehim.com\/#website\",\"url\":\"https:\/\/codehim.com\/\",\"name\":\"CodeHim\",\"description\":\"Web Design Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/codehim.com\/#organization\"},\"alternateName\":\"Web Design Codes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/codehim.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/codehim.com\/#organization\",\"name\":\"CodeHim - Web Design Code & Scripts\",\"url\":\"https:\/\/codehim.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/codehim.com\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/codehim.com\/wp-content\/uploads\/2023\/06\/Codehim-short-logo.jpg\",\"contentUrl\":\"http:\/\/codehim.com\/wp-content\/uploads\/2023\/06\/Codehim-short-logo.jpg\",\"width\":280,\"height\":280,\"caption\":\"CodeHim - Web Design Code & Scripts\"},\"image\":{\"@id\":\"https:\/\/codehim.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/codehimofficial\",\"https:\/\/x.com\/CodeHimOfficial\",\"https:\/\/www.instagram.com\/codehim\/\",\"https:\/\/www.linkedin.com\/company\/codehim\",\"https:\/\/co.pinterest.com\/codehim\/\",\"https:\/\/www.youtube.com\/@codehim\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/codehim.com\/#\/schema\/person\/cc48f1dbe072a89a62a98171b7db43ed\",\"name\":\"Asif Mughal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/codehim.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b25bfcd7d4e341c2c6f785a88d8ad2a4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b25bfcd7d4e341c2c6f785a88d8ad2a4?s=96&d=mm&r=g\",\"caption\":\"Asif Mughal\"},\"description\":\"I code and create web elements for amazing people around the world. I like work with new people. New people new Experiences. I truly enjoy what I'm doing, which makes me more passionate about web development and coding. I am always ready to do challenging tasks whether it is about creating a custom CMS from scratch or customizing an existing system.\",\"sameAs\":[\"https:\/\/codehim.com\"],\"url\":\"https:\/\/codehim.com\/author\/asif-mughal\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JavaScript Sort Table on Header Click &#8212; CodeHim","description":"Here is a lightweight JavaScript code snippet to sort table on header click. You can view demo and download source code.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript Sort Table on Header Click &#8212; CodeHim","og_description":"Here is a lightweight JavaScript code snippet to sort table on header click. You can view demo and download source code.","og_url":"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/","og_site_name":"CodeHim","article_publisher":"https:\/\/www.facebook.com\/codehimofficial","article_published_time":"2024-01-11T16:46:00+00:00","article_modified_time":"2024-01-22T09:47:16+00:00","og_image":[{"width":1280,"height":959,"url":"https:\/\/codehim.com\/wp-content\/uploads\/2022\/05\/javascript-sort-table-on-header-click_.png","type":"image\/png"}],"author":"Asif Mughal","twitter_card":"summary_large_image","twitter_creator":"@CodeHimOfficial","twitter_site":"@CodeHimOfficial","twitter_misc":{"Written by":"Asif Mughal","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/#article","isPartOf":{"@id":"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/"},"author":{"name":"Asif Mughal","@id":"https:\/\/codehim.com\/#\/schema\/person\/cc48f1dbe072a89a62a98171b7db43ed"},"headline":"JavaScript Sort Table on Header Click","datePublished":"2024-01-11T16:46:00+00:00","dateModified":"2024-01-22T09:47:16+00:00","mainEntityOfPage":{"@id":"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/"},"wordCount":153,"commentCount":0,"publisher":{"@id":"https:\/\/codehim.com\/#organization"},"image":{"@id":"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/#primaryimage"},"thumbnailUrl":"https:\/\/codehim.com\/wp-content\/uploads\/2022\/05\/javascript-sort-table-on-header-click_.png","articleSection":["Vanilla JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/","url":"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/","name":"JavaScript Sort Table on Header Click &#8212; CodeHim","isPartOf":{"@id":"https:\/\/codehim.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/#primaryimage"},"image":{"@id":"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/#primaryimage"},"thumbnailUrl":"https:\/\/codehim.com\/wp-content\/uploads\/2022\/05\/javascript-sort-table-on-header-click_.png","datePublished":"2024-01-11T16:46:00+00:00","dateModified":"2024-01-22T09:47:16+00:00","description":"Here is a lightweight JavaScript code snippet to sort table on header click. You can view demo and download source code.","breadcrumb":{"@id":"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/#primaryimage","url":"https:\/\/codehim.com\/wp-content\/uploads\/2022\/05\/javascript-sort-table-on-header-click_.png","contentUrl":"https:\/\/codehim.com\/wp-content\/uploads\/2022\/05\/javascript-sort-table-on-header-click_.png","width":1280,"height":959,"caption":"JavaScript Sort Table on Header Click"},{"@type":"BreadcrumbList","@id":"https:\/\/codehim.com\/vanilla-javascript\/javascript-sort-table-on-header-click\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codehim.com\/"},{"@type":"ListItem","position":2,"name":"Vanilla JavaScript","item":"https:\/\/codehim.com\/category\/vanilla-javascript\/"},{"@type":"ListItem","position":3,"name":"JavaScript Sort Table on Header Click"}]},{"@type":"WebSite","@id":"https:\/\/codehim.com\/#website","url":"https:\/\/codehim.com\/","name":"CodeHim","description":"Web Design Code Snippets","publisher":{"@id":"https:\/\/codehim.com\/#organization"},"alternateName":"Web Design Codes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codehim.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/codehim.com\/#organization","name":"CodeHim - Web Design Code & Scripts","url":"https:\/\/codehim.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codehim.com\/#\/schema\/logo\/image\/","url":"http:\/\/codehim.com\/wp-content\/uploads\/2023\/06\/Codehim-short-logo.jpg","contentUrl":"http:\/\/codehim.com\/wp-content\/uploads\/2023\/06\/Codehim-short-logo.jpg","width":280,"height":280,"caption":"CodeHim - Web Design Code & Scripts"},"image":{"@id":"https:\/\/codehim.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codehimofficial","https:\/\/x.com\/CodeHimOfficial","https:\/\/www.instagram.com\/codehim\/","https:\/\/www.linkedin.com\/company\/codehim","https:\/\/co.pinterest.com\/codehim\/","https:\/\/www.youtube.com\/@codehim"]},{"@type":"Person","@id":"https:\/\/codehim.com\/#\/schema\/person\/cc48f1dbe072a89a62a98171b7db43ed","name":"Asif Mughal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codehim.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b25bfcd7d4e341c2c6f785a88d8ad2a4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b25bfcd7d4e341c2c6f785a88d8ad2a4?s=96&d=mm&r=g","caption":"Asif Mughal"},"description":"I code and create web elements for amazing people around the world. I like work with new people. New people new Experiences. I truly enjoy what I'm doing, which makes me more passionate about web development and coding. I am always ready to do challenging tasks whether it is about creating a custom CMS from scratch or customizing an existing system.","sameAs":["https:\/\/codehim.com"],"url":"https:\/\/codehim.com\/author\/asif-mughal\/"}]}},"views":7235,"_links":{"self":[{"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/posts\/6568","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/comments?post=6568"}],"version-history":[{"count":0,"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/posts\/6568\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/media\/7039"}],"wp:attachment":[{"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/media?parent=6568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/categories?post=6568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/tags?post=6568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}