Created
March 13, 2014 21:43
-
-
Save gileno/9537587 to your computer and use it in GitHub Desktop.
Simples código para toggle em uma tabela
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
$.fn.selectAll = function(options) { | |
var defaults = { | |
inputs: 'input[name=ids]', | |
selectAll: "#select_all", | |
selected: false | |
}; | |
var settings = $.extend(defaults, options); | |
return this.each(function(x) { | |
var table = $(this); | |
var selectAll = table.find(settings.selectAll); | |
var inputs = table.find(settings.inputs); | |
selectAll.click(function(e){ | |
var select = $(this); | |
if(select.is(":checked")) { | |
inputs.attr("checked", true); | |
} else { | |
inputs.attr("checked", false); | |
} | |
}); | |
inputs.click(function(e){ | |
var length = inputs.length; | |
var lengthChecked = inputs.filter(":checked").length; | |
if(length == lengthChecked) { | |
selectAll.attr("checked", true); | |
} else { | |
selectAll.attr("checked", false); | |
} | |
}); | |
if(settings.selected) { | |
selectAll.attr("checked", true); | |
inputs.attr("checked", true); | |
} | |
}); | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment