Skip to content

Commit

Permalink
fixed issue #158.
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyGermaneri committed Dec 24, 2018
1 parent d67b566 commit 5481270
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 32 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ canvas-datagrid
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
[![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/TonyGermaneri/canvas-datagrid)

* Support for unlimited rows and columns without paging or loading.
* Drawn in immediate mode, data size does not impact performance.

* Works with Firefox, IE11, Edge, Safari and Chrome.
* Native support for touch devices (phones and tablets).
* Extensible styling, filtering, formatting, resizing, selecting, and ordering.
* Rich [documentation](https://tonygermaneri.github.io/canvas-datagrid/docs/), [tutorials](https://tonygermaneri.github.io/canvas-datagrid/docs/index.html#tutorials), and [slack support](https://canvas-datagrid.slack.com/).
* Single canvas element, drawn in immediate mode, data size does not impact performance.
* Support for unlimited rows and columns without paging or loading.
* Rich API of events, methods and properties using the familiar W3C DOM interface.
* Works with Firefox, IE11, Edge, Safari and Chrome.
* Extensible styling, filtering, formatting, resizing, selecting, and ordering.
* Support for hierarchal drill in style row level inner grids as well grids in cells.
* Support for freezing columns and rows.
* Customizable hierarchal context menu.
* Built in and custom styles.
* W3C Web Component. Works in all frameworks.
Expand All @@ -28,7 +29,7 @@ canvas-datagrid

[Tutorials](https://tonygermaneri.github.io/canvas-datagrid/docs/index.html#tutorials)

[Slack Support](https://canvas-datagrid.slack.com/)
[Slack Support](https://canvas-datagrid.slack.com/) (message author for invite)

[Style Builder](https://tonygermaneri.github.io/canvas-datagrid/tutorials/styleBuilder.html)

Expand Down
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2033
2034
31 changes: 20 additions & 11 deletions dist/canvas-datagrid.debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/canvas-datagrid.debug.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/canvas-datagrid.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/canvas-datagrid.map

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,22 +458,28 @@ define([], function () {
};
self.click = function (e, overridePos) {
var i,
startingBounds = JSON.stringify(self.getSelectionBounds()),
ctrl = (e.ctrlKey || e.metaKey || self.attributes.persistantSelectionMode),
pos = overridePos || self.getLayerPos(e);
self.currentCell = self.getCellAt(pos.x, pos.y);
if (self.currentCell.grid !== undefined) {
return;
}
function checkSelectionChange() {
var ev = {
var ev, sb = self.getSelectionBounds();
if (startingBounds === JSON.stringify(sb)) {
return;
}
ev = {
selections: self.selections,
selectionBounds: self.selectionBounds
selectionBounds: self.getSelectionBounds()
};
Object.defineProperty(ev, 'selectedData', {
get: function () {
return self.getSelectedData();
}
});
self.dispatchEvent('selectionchanged', ev);
}
if (self.input) {
self.endEdit();
Expand Down Expand Up @@ -509,8 +515,7 @@ define([], function () {
return;
}
if (self.attributes.columnHeaderClickBehavior === 'select') {
self.selectColumn(i.header.index, ctrl, e.shiftKey, true);
checkSelectionChange();
self.selectColumn(i.header.index, ctrl, e.shiftKey);
self.draw();
return;
}
Expand Down Expand Up @@ -832,7 +837,7 @@ define([], function () {
self.selecting = true;
if ((self.attributes.selectionMode === 'row' || self.dragStartObject.columnIndex === -1)
&& self.dragStartObject.rowIndex > -1) {
self.selectRow(self.dragStartObject.rowIndex, ctrl, null, true);
self.selectRow(self.dragStartObject.rowIndex, ctrl, null);
} else if (self.attributes.selectionMode !== 'row') {
self.mousemove(e);
}
Expand Down
16 changes: 10 additions & 6 deletions lib/publicMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,14 @@ define([], function () {
*/
self.selectRow = function (rowIndex, ctrl, shift, supressEvent) {
var x, st, en, s = self.getVisibleSchema();
function de() {
if (supressEvent) { return; }
self.dispatchEvent('selectionchanged', {
selectedData: self.getSelectedData(),
selections: self.selections,
selectionBounds: self.selectionBounds
});
}
function addRow(ri) {
self.selections[ri] = [];
self.selections[ri].push(-1);
Expand All @@ -464,6 +472,7 @@ define([], function () {
if (self.selections[rowIndex] && self.selections[rowIndex].length - 1 === s.length) {
if (ctrl) {
self.selections[rowIndex] = [];
de();
return;
}
}
Expand All @@ -480,12 +489,7 @@ define([], function () {
addRow(rowIndex);
}
}
if (supressEvent) { return; }
self.dispatchEvent('selectionchanged', {
selectedData: self.getSelectedData(),
selections: self.selections,
selectionBounds: self.selectionBounds
});
de();
};
/**
* Collapse a tree grid by row index.
Expand Down
4 changes: 4 additions & 0 deletions tutorials/developer.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
window.addEventListener('load', function () {
var parentNode = document.getElementById('grid');
var grid = document.createElement('canvas-datagrid');
grid.setAttribute('columnHeaderClickBehavior', 'select');
parentNode.appendChild(grid);
grid.data = [
{col0: '0foo', col1: 'foo', col2: 0, col3: 'a', col4: 'test', col5: 'test2'},
Expand Down Expand Up @@ -45,6 +46,9 @@
}
];
grid.columnOrder = [4, 5, 2, 1, 0, 3]; // if called, clicking on a x-axis header will select a full row.
grid.addEventListener('selectionchanged', function () {
console.log('change')
});
});
</script>

Expand Down

0 comments on commit 5481270

Please sign in to comment.