{"id":121,"date":"2024-12-27T19:23:31","date_gmt":"2024-12-27T22:23:31","guid":{"rendered":"https:\/\/recover.rdconsolo.com.br\/?p=121"},"modified":"2024-12-27T19:34:29","modified_gmt":"2024-12-27T22:34:29","slug":"selecao-global-dos-elementos-da-coluna-em-tabelas-html","status":"publish","type":"post","link":"https:\/\/rdconsolo.com.br\/?p=121","title":{"rendered":"Sele\u00e7\u00e3o global dos elementos da coluna em tabelas html"},"content":{"rendered":"\n<p>Em casos onde temos mais de uma coluna com o recurso de sele\u00e7\u00e3o global dentro de uma tabela html, podemos usar o exemplo abaixo para controlar qual elemento foi selecionado.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"markup\" class=\"language-markup line-numbers\">&lt;th data-sortable=\"false\" width=\"150px\" class=\"text-danger\"&gt;\n    &lt;input class=\"form-check-input\" type=\"checkbox\" id=\"chkSelectAllRem\" \/&gt;\n    &lt;label for=\"chkSelectAllRem\"&gt;Todas\/Nenhuma&lt;\/label&gt;\n&lt;\/th&gt;\n&lt;th data-sortable=\"false\" width=\"150px\" class=\"text-success\"&gt;\n    &lt;input class=\"form-check-input\" type=\"checkbox\" id=\"chkSelectAllEnc\" \/&gt;\n    &lt;label for=\"chkSelectAllEnc\"&gt;Todas\/Nenhuma&lt;\/label&gt;\n&lt;\/th&gt;\n\n...\n\n&lt;td&gt;\n    &lt;div class=\"form-check\"&gt;\n        &lt;input class=\"form-check-input\" type=\"checkbox\" name=\"op_rem[]\" value=\"&lt;?= $row-&gt;id_pr_ordens ?&gt;\"\n               id=\"op_rem.&lt;?= $row-&gt;id_pr_ordens ?&gt;\"&gt;\n        &lt;label class=\"form-check-label text-danger\" for=\"op_rem.&lt;?= $row-&gt;id_pr_ordens ?&gt;\"&gt;Remover&lt;\/label&gt;\n    &lt;\/div&gt;\n&lt;\/td&gt;\n&lt;td&gt;\n    &lt;div class=\"form-check\"&gt;\n        &lt;input class=\"form-check-input\" type=\"checkbox\" name=\"op_enc[]\" value=\"&lt;?= $row-&gt;id_pr_ordens ?&gt;\"\n               id=\"op_enc.&lt;?= $row-&gt;id_pr_ordens ?&gt;\" \/&gt;\n        &lt;label class=\"form-check-label text-success\" for=\"op_enc.&lt;?= $row-&gt;id_pr_ordens ?&gt;\"&gt;Encerrar&lt;\/label&gt;\n    &lt;\/div&gt;\n&lt;\/td&gt;\n\n...\n\n&lt;script&gt;\n$(\"th input[type='checkbox']\").on(\"change\", function() {\n    \/\/ remove sele\u00e7\u00e3o de todos checkboxes\n    $('input[type=\"checkbox\"]').not(this).prop(\"checked\", false);\n    \/\/ seleciona todos os elemento da coluna selecionada\n    var cb = $(this), \/\/ checkbox that was changed\n        th = cb.parent(), \/\/ get parent th\n        col = th.index() + 1; \/\/ get column index. note nth-child starts at 1, not zero\n    $(\"tbody td:nth-child(\" + col + \") input\").prop(\"checked\", this.checked); \/\/ select the inputs and [un]check it\n});\n\n$(document).ready(function() {\n    \/\/ uncheck other boxes on the same row\n    $(\".form-check-input\").click(function() {\n        $('input[type=\"checkbox\"]').change(function() {\n            $(this).closest('tr').find('input[type=\"checkbox\"]').not(this).prop('checked', false);\n        });\n    });\n});\n&lt;\/script&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Em casos onde temos mais de uma coluna com o recurso de sele\u00e7\u00e3o global dentro de uma tabela html, podemos usar o exemplo abaixo para controlar qual elemento foi selecionado.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[34],"class_list":["post-121","post","type-post","status-publish","format-standard","hentry","category-developer","tag-jquery"],"_links":{"self":[{"href":"https:\/\/rdconsolo.com.br\/index.php?rest_route=\/wp\/v2\/posts\/121","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rdconsolo.com.br\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rdconsolo.com.br\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rdconsolo.com.br\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rdconsolo.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=121"}],"version-history":[{"count":2,"href":"https:\/\/rdconsolo.com.br\/index.php?rest_route=\/wp\/v2\/posts\/121\/revisions"}],"predecessor-version":[{"id":135,"href":"https:\/\/rdconsolo.com.br\/index.php?rest_route=\/wp\/v2\/posts\/121\/revisions\/135"}],"wp:attachment":[{"href":"https:\/\/rdconsolo.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rdconsolo.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=121"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rdconsolo.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}