JavaScript Javascript html table hidding columns javascript html table to csv,javascript html table library,javascript

I have developed this neat little piece of code which given an element and a properly formatted table, creates a dropdown menu on the element which allows the user to toggle view of columns.

I cannot figure out how to make the changes (which columns to stay hidden) persists on page change, as it is a usual pattern to have a table on a page with pagination.

fiddle: https://jsfiddle.net/mssrq8ah/

my html markup:

<table id="table">
    <thead>
        <tr>
            <th>h1</th><th>h2</th><th>h3</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>a1</td><td>a2</td><td>a3</td>
        </tr>
        <tr>
            <td>b1</td><td>b2</td><td>b3</td>
        </tr>
   </tbody>
</table>
<button id="list">drop</button>

my js function:

table_hide("#list","#table")
function table_hide( button , table)
         {

             jQuery(button).attr("data-toggle","dropdown");
             jQuery(button).addClass("dropdown-toggle");
             jQuery(button).wrap("<div class='btn-group'>");
             var list = "";
             jQuery("thead").find("tr").first().find("th").each(function(index,element){
                 list = list + "<li>" +
                "<div class='checkbox col-md-6'><label><input type='checkbox' checked value='"+index+"' class='td_hide'>"+jQuery(element).text()+"</label></div>"+
                "</li>";
             });
             jQuery(button).after("<ul class='dropdown-menu col-md-12'>"+list+"</ul>");


            jQuery(".td_hide").on("click",function(){
                        var target_column = jQuery(this).val();
                        jQuery("tr").each(function(index , element){

                            jQuery(this).find("th , td").eq(target_column).toggle();
                        });   
                });

            jQuery(".dropdown-menu").find("select , .ws-popover-opener , .step-control").on("click",function(e){
                e.stopPropagation();
                });
         }

if at all possible i would like to avoid any more needed libraries as i intent to use it on CMS, and jQuery/bootstrap is the standard these days.

Answer:1

To understand async/await, I am trying to display a console message once settimeout runs and expires. How do I fix my code below? I have 5 settimeout function and each should display respective ...

To understand async/await, I am trying to display a console message once settimeout runs and expires. How do I fix my code below? I have 5 settimeout function and each should display respective ...

  1. using async await
  2. using async await c#
  3. using async await javascript
  4. using async await in node js
  5. using async await in react
  6. using async await mongoose
  7. using async await in node
  8. using async await axios
  9. using async await and promises
  10. using async await fetch
  11. use async await in angular 6
  12. using async without await
  13. using async await with callback functions
  14. async with await
  15. async with await python
  16. async with await c#
  17. use effect async await
  18. why use async await in web api

Hi i'm using Jquery Upload plugin. I've got this problem: when i upload the first file this work fine,a single request is sent. But if i select a second file and i upload it,two request are sent and ...

Hi i'm using Jquery Upload plugin. I've got this problem: when i upload the first file this work fine,a single request is sent. But if i select a second file and i upload it,two request are sent and ...

  1. when do we choose another president

I've tried to render a simple component but cant seem to make it work. <Col md={{ span: 16, offset: 4 }} xs={{ span: 20, offset: 2 }}> {props.language === "en" ? <englishReport /> : &...

I've tried to render a simple component but cant seem to make it work. <Col md={{ span: 16, offset: 4 }} xs={{ span: 20, offset: 2 }}> {props.language === "en" ? <englishReport /> : &...

I have a scenario to get a output like the following. 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 When the input is 3 it would give 8 combinations as above. If the input is 4, there would be 16 ...

I have a scenario to get a output like the following. 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 When the input is 3 it would give 8 combinations as above. If the input is 4, there would be 16 ...

  1. recursive loop python
  2. recursive loop detected in template string
  3. recursive loop java
  4. recursive loop javascript
  5. recursive loop definition
  6. recursive loop c++
  7. recursive loop r
  8. recursive loop matlab
  9. recursive loop example
  10. recursive loop array javascript
  11. recursive loop in sql server
  12. recursive loop in oracle sql
  13. recursive loop php
  14. recursive loop knime
  15. recursive loop js
  16. recursive loop in angular 6
  17. recursive loop in jquery
  18. recursive loop in pl sql
  19. recursive loop start knime
  20. recursive loop through json