{"id":635,"date":"2012-01-24T13:31:10","date_gmt":"2012-01-24T21:31:10","guid":{"rendered":"http:\/\/www.auval.com.mx\/notas\/?p=635"},"modified":"2012-01-24T13:31:10","modified_gmt":"2012-01-24T21:31:10","slug":"como-ordenar-una-lista","status":"publish","type":"post","link":"https:\/\/auval.com.mx\/blog\/2012\/01\/24\/como-ordenar-una-lista\/","title":{"rendered":"C\u00f3mo ordenar una lista"},"content":{"rendered":"<p>Esta es una pregunta que me surgi\u00f3 al estar dise\u00f1ando una lista reordenable por el usuario. Es un tema b\u00e1sico, pero como me tard\u00e9 en recordar c\u00f3mo se hac\u00eda, anexo los pasos.<\/p>\n<p>&nbsp;<\/p>\n<table width=\"256\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><strong><span style=\"font-family: Calibri;\">ID<\/span><\/strong><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><strong><span style=\"font-family: Calibri;\">Texto<\/span><\/strong><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><strong><span style=\"font-family: Calibri;\">Sig<\/span><\/strong><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><strong><span style=\"font-family: Calibri;\">Ant<\/span><\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">1<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">a<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">2<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">-1<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">2<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">b<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">3<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">1<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">3<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">c<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">4<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">2<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">4<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">d<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">5<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">3<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">5<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">e<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">6<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">4<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">6<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">f<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">7<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">5<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">7<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">g<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">8<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">6<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">8<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">h<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">9<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">7<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">9<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">i<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">10<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">8<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">10<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">j<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">1000<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">9<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-size: small;\"><span style=\"color: #000000;\"><span style=\"font-family: Calibri;\"> Esta es una lista.<\/span><\/span><\/span><\/p>\n<p><span style=\"color: #000000; font-family: Calibri; font-size: small;\">\u00a0<\/span><\/p>\n<p><span style=\"font-size: small;\"><span style=\"color: #000000;\"><span style=\"font-family: Calibri;\">El primer registro tendr\u00e1 esta forma.<\/span><\/span><\/span><\/p>\n<table width=\"256\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><strong><span style=\"font-family: Calibri;\">ID<\/span><\/strong><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><strong><span style=\"font-family: Calibri;\">Texto<\/span><\/strong><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><strong><span style=\"font-family: Calibri;\">Sig<\/span><\/strong><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><strong><span style=\"font-family: Calibri;\">Ant<\/span><\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">1<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">a<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">1000<\/span><\/p>\n<\/td>\n<td valign=\"bottom\" nowrap=\"nowrap\" width=\"64\">\n<p align=\"center\"><span style=\"font-family: Calibri;\">-1<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"color: #000000; font-family: Calibri; font-size: small;\">\u00a0<\/span><\/p>\n<p><span style=\"font-size: small;\"><span style=\"color: #000000;\"><span style=\"font-family: Calibri;\">Para insertar un registro despu\u00e9s de un registro \u201cbase\u201d, haremos lo siguiente:<\/span><\/span><\/span><\/p>\n<p><span style=\"color: #000000; font-family: Calibri; font-size: small;\">\u00a0<\/span><\/p>\n<p><span style=\"font-size: small;\"><span style=\"color: #000000;\"><span style=\"font-family: Calibri;\">base.sig = insertado.id<\/span><\/span><\/span><\/p>\n<p><span style=\"font-size: small;\"><span style=\"color: #000000;\"><span style=\"font-family: Calibri;\">insertado.sig = base.sig<\/span><\/span><\/span><\/p>\n<p><span style=\"color: #000000; font-family: Calibri; font-size: small;\">\u00a0<\/span><\/p>\n<p><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\">base+ 1.ant = <strong>insertado<\/strong><\/span><span style=\"color: #000000;\">.id<\/span><\/span><\/span><\/p>\n<p><span style=\"font-family: Calibri;\"><span style=\"font-size: small;\"><strong><span style=\"color: #000000;\">insertado<\/span><\/strong><span style=\"color: #000000;\">.ant = base + 1.ant<\/span><\/span><\/span><\/p>\n<p><span style=\"color: #000000; font-family: Calibri; font-size: small;\">\u00a0<\/span><\/p>\n<p><span style=\"font-size: small;\"><span style=\"color: #000000;\"><span style=\"font-family: Calibri;\">Para borrar un registro, haremos lo siguiente:<\/span><\/span><\/span><\/p>\n<p><span style=\"color: #000000; font-family: Calibri; font-size: small;\">\u00a0<\/span><\/p>\n<p><span style=\"font-size: small;\"><span style=\"color: #000000;\"><span style=\"font-family: Calibri;\">borrado &#8211; 1.sig = borrado.sig<\/span><\/span><\/span><\/p>\n<p><span style=\"font-size: small;\"><span style=\"color: #000000;\"><span style=\"font-family: Calibri;\">borrado + 1.ant = borrado.ant<\/span><\/span><\/span><\/p>\n<p><span style=\"font-size: small;\"><span style=\"color: #000000;\"><span style=\"font-family: Calibri;\">Y luego borramos el registro.<\/span><\/span><\/span><\/p>\n<p><span style=\"color: #000000; font-family: Calibri; font-size: small;\">\u00a0<\/span><\/p>\n<p><span style=\"font-size: small;\"><span style=\"color: #000000;\"><span style=\"font-family: Calibri;\">Para mover un registro para que quede despu\u00e9s de un registro \u201cbase\u201d, haremos lo siguiente:<\/span><\/span><\/span><\/p>\n<p><span style=\"color: #000000; font-family: Calibri; font-size: small;\">\u00a0<\/span><\/p>\n<p><span style=\"font-size: small;\"><span style=\"color: #000000;\"><span style=\"font-family: Calibri;\">base.sig = movido.id<\/span><\/span><\/span><\/p>\n<p><span style=\"font-size: small;\"><span style=\"color: #000000;\"><span style=\"font-family: Calibri;\">movido.sig = base.sig<\/span><\/span><\/span><\/p>\n<p><span style=\"font-size: small;\"><span style=\"color: #000000;\"><span style=\"font-family: Calibri;\">movido \u2013 1.sig = movido.sig<\/span><\/span><\/span><\/p>\n<p><span style=\"color: #000000; font-family: Calibri; font-size: small;\">\u00a0<\/span><\/p>\n<p><span style=\"font-size: small;\"><span style=\"color: #000000;\"><span style=\"font-family: Calibri;\">base + 1.ant = movido + 1.ant<\/span><\/span><\/span><\/p>\n<p><span style=\"font-size: small;\"><span style=\"color: #000000;\"><span style=\"font-family: Calibri;\">movido.ant = base.id<\/span><\/span><\/span><\/p>\n<p><span style=\"font-size: small;\"><span style=\"color: #000000;\"><span style=\"font-family: Calibri;\">movido + 1.ant = movido.ant<\/span><\/span><\/span><\/p>\n<p><span style=\"color: #000000; font-family: Calibri; font-size: small;\">\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Esta es una pregunta que me surgi\u00f3 al estar dise\u00f1ando una lista reordenable por el usuario. Es un tema b\u00e1sico, pero como me tard\u00e9 en recordar c\u00f3mo se hac\u00eda, anexo los pasos. &nbsp; ID Texto Sig Ant 1 a 2 &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/auval.com.mx\/blog\/2012\/01\/24\/como-ordenar-una-lista\/\"> <span class=\"screen-reader-text\">C\u00f3mo ordenar una lista<\/span> Leer m\u00e1s \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-635","post","type-post","status-publish","format-standard","hentry","category-temas_varios"],"_links":{"self":[{"href":"https:\/\/auval.com.mx\/blog\/wp-json\/wp\/v2\/posts\/635","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/auval.com.mx\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/auval.com.mx\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/auval.com.mx\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/auval.com.mx\/blog\/wp-json\/wp\/v2\/comments?post=635"}],"version-history":[{"count":0,"href":"https:\/\/auval.com.mx\/blog\/wp-json\/wp\/v2\/posts\/635\/revisions"}],"wp:attachment":[{"href":"https:\/\/auval.com.mx\/blog\/wp-json\/wp\/v2\/media?parent=635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/auval.com.mx\/blog\/wp-json\/wp\/v2\/categories?post=635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/auval.com.mx\/blog\/wp-json\/wp\/v2\/tags?post=635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}