Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickocoffeyo committed Nov 21, 2013
0 parents commit 9f8f85f
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
20 changes: 20 additions & 0 deletions LICENSE
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2013 Patrick Coffey

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4 changes: 4 additions & 0 deletions README.md
@@ -0,0 +1,4 @@
jquery-table-operations
=======================

Easily create tables with select-able rows, and operations that can be performed on the selected rows.
46 changes: 46 additions & 0 deletions jquery.tableOperations.js
@@ -0,0 +1,46 @@
(function($) {

$.fn.tableOperations = function(options) {
var $table = $(this),
$form = {},
$select = {},
defaults = {
defaultSelect: 'Select',
selectClass: 'form-control',
buttonClass: 'btn btn-default',
formClass: 'form-inline',
buttonText: 'Go',
operations: {
test: { label: 'Test Me', callback: function(selected) { console.log(selected); } }
}
};

options = $.extend({}, defaults, options);

//Add the checkbox tds
if ($table.find('thead').length <= 0) { $table.prepend('<thead><tr></tr></thead>'); }
$table.find('tr').prepend('<td class="batch-select-check"><input type="checkbox"/></td>');

//Add the operations selector box
$table.before('<form id="batch-select-operation-form" class="'+options.formClass+'" role="form"><div class="form-group"><select class="'+options.selectClass+'"><option>'+options.defaultSelect+'</option></select></div><div class="form-group"><button type="submit" class="'+options.buttonClass+'">'+options.buttonText+'</button></div>');
$form = $('form#batch-select-operation-form');
$select = $form.find('select');
$.each(options.operations, function(index, item) { $select.append('<option value="'+index+'">'+item.label+'</option>'); });

//check all
$table.find('thead td.batch-select-check input').on('click', function() {
$table.find('td.batch-select-check input').prop('checked', $(this).prop('checked') );
});

//Form submition actions
$form.on('submit', function(e) {
e.preventDefault();
var val = $(this).find('select').val(),
$selected = $table.find('.batch-select-check input:checked').closest('tr');

if (val != options.defaultSelect && $selected.length > 0) { options.operations[val].callback($selected); }
});

};

})(jQuery);
35 changes: 35 additions & 0 deletions tableOperations.jquery.json
@@ -0,0 +1,35 @@
{
"name": "tableOperations",
"title": "tableOperations",
"description": "Easily create tables with select-able rows, and operations that can be performed on the selected rows.",
"keywords": [
"jquery",
"table",
"batch",
"operations"
],
"version": "0.0.1",
"author": {
"name": "Patrick Coffey",
"url": "http://scriptsquirrel.com"
},
"maintainers": [
{
"name": "Patrick Coffey",
"url": "http://scriptsquirrel.com"
}
],
"licenses": [
{
"type": "MIT",
"url": "https://raw.github.com/patrickocoffeyo/jquery-table-operations/master/LICENSE"
}
],
"bugs": "https://github.com/patrickocoffeyo/jquery-table-operations/issues",
"homepage": "http://scriptsquirrel.com",
"docs": "https://github.com/patrickocoffeyo/jquery-table-operations/blob/master/README.md",
"download": "https://github.com/patrickocoffeyo/jquery-table-operations/archive/master.zip",
"dependencies": {
"jquery": ">=1.4"
}
}

0 comments on commit 9f8f85f

Please sign in to comment.