Skip to content

Directive options #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.log
.idea/
*.iml
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ angular.module("app", ["ui.grid", "ui.grid.custom-cell-select"]);
To add custom cell selection functionality you have to insert `ui-grid-custom-cell-select` directive to your table.

```html
<div ui-grid="gridOptions" class="grid" ui-grid-custom-cell-select></div>
<div ui-grid="gridOptions" class="grid" ui-grid-custom-cell-select="selectOptions"></div>
```

## Settings

An object may be provided to the `ui-grid-custom-cell-select` attribute.

- `ignoreRightClick` - (Default: false) Will not begin dragging when right mouse is used. Useful for context menus.

## Additional styling
When you select grid cells ann additional css class (`ui-grid-draggable-row-over`) is applied to them. This plugin has default styling for these elements. If you are using __less__ you could import styles into your application.

Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "ui-grid-custom-cell-select",
"version": "0.1.2",
"version": "0.2.0",
"authors": [
"Brenden Peterson <brendenjpeterson@gmail.com>"
],
"description": "Custom Cell Selection Plugin for UI Grid",
"main": "js/draggable-rows.js",
"main": "js/custom-cell-select.js",
"moduleType": [
"globals"
],
Expand Down
29 changes: 29 additions & 0 deletions js/custom-cell-select.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
// Custom multi-cell selection directive for UI-Grid
// Created by brendenjpeterson@gmail.com

/**
* @typedef {Object} SelectionOptions
* @property {Boolean} ignoreRightClick=false Set to true to ignore right click events
*/

angular.module('ui.grid')
.directive('uiGridCustomCellSelect', ['$timeout', '$document', '$filter', 'rowSearcher', 'uiGridConstants', function ($timeout, $document, $filter, rowSearcher, uiGridConstants) {

// Adapted From https://www.quirksmode.org/js/events_properties.html
// Quick test to check mouse events for right click
function isRightMouse(evt) {
if (evt.which) { return (evt.which === 3); }
else if (evt.button) { return (evt.button === 2); }
return false;
}

/**
* @type {SelectionOptions}
*/
var defaultOptions = {
ignoreRightClick: false
};

return {
replace: true,
require: '^uiGrid',
Expand All @@ -15,6 +36,10 @@ angular.module('ui.grid')
var _scope = $scope;
var grid = uiGridCtrl.grid;

/**
* @type {SelectionOptions}
*/
var selectionOptions = angular.extend({}, defaultOptions, $scope.$eval( $attrs.uiGridCustomCellSelect ));

// Data setup
_scope.ugCustomSelect = {
Expand Down Expand Up @@ -55,6 +80,10 @@ angular.module('ui.grid')

// Events
function dragStart(evt) {

// Ignore right mouse if specified in options
if( selectionOptions.ignoreRightClick && isRightMouse(evt) ){ return; }

if (angular.element(evt.target).hasClass('ui-grid-cell-contents')) {
var cellData = $(this).data().$scope;
clearDragData();
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ui-grid-custom-cell-select",
"version": "0.2.0",
"description": "Custom Cell Selection Plugin for UI Grid",
"main": "js/draggable-rows.js",
"main": "js/custom-cell-select.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand All @@ -23,6 +23,10 @@
{
"name": "Jairo Alejandro Honorio Diaz",
"email": "registrofx@gmail.com"
},
{
"name": "Michael Grill",
"email": "mike@gogrillion.com"
}
],
"license": "MIT",
Expand Down