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.
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 ...
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 ...
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 ...