Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
add filter button
Browse files Browse the repository at this point in the history
Adds a filter button to toggle columns.  All have 'active' class to
start and it is toggled on click to show which columns you have hidden.
  • Loading branch information
Drew Rothstein committed Jan 26, 2013
1 parent 6ddba60 commit ee52a90
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
21 changes: 21 additions & 0 deletions www/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ function change_cost(duration) {
current_cost_duration = duration;
}

function column_toggle_setup() {
// get column headings, add to filter button
$.each($("#data thead tr th"), function(i, elem) {
$("#filter-dropdown ul").append("<li class=\"active\"><a href=\"javascript:;\" onclick=\"fnShowHide("+i+");\">"+elem.innerText+"</a></li>");
});

// toggle column buttons
$("#filter-dropdown ul.dropdown-menu li").bind("click", function(e) {
$(this).toggleClass("active");
});
}

$(function() {
$(document).ready(function() {
$('#data').dataTable({
Expand All @@ -60,6 +72,8 @@ $(function() {
});

change_cost('hourly');

column_toggle_setup();
});

$("#cost-dropdown li").bind("click", function(e) {
Expand All @@ -85,3 +99,10 @@ jQuery.extend(jQuery.fn.dataTableExt.oSort, {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
});

// toggle columns
function fnShowHide(iCol) {
var oTable = $('#data').dataTable();
var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
oTable.fnSetColumnVis( iCol, bVis ? false : true );
}
10 changes: 10 additions & 0 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ <h1>EC2Instances.info <small>Easy Amazon EC2 Instance Comparison</small></h1>
<li><a href="javascript:;" duration="yearly">Yearly</a></li>
</ul>
</div>

<div class="btn-group" id="filter-dropdown">
<a class="btn dropdown-toggle btn-primary" data-toggle="dropdown" href="#">
<i class="icon-filter icon-white"></i>
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<!-- table header elements inserted by js -->
</ul>
</div>
</div>

<table cellspacing="0" class="table table-bordered table-hover table-condensed" id="data">
Expand Down

0 comments on commit ee52a90

Please sign in to comment.