Skip to content

Commit

Permalink
Merge pull request #28 from TonyGermaneri/june-bug-fixes
Browse files Browse the repository at this point in the history
Fixed multifilter remove.  Fixed selection drag bug.  Fixed stored order bug.
  • Loading branch information
TonyGermaneri committed Jun 27, 2017
2 parents d5da6e0 + 549332f commit 2e81a34
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 62 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "canvas-datagrid",
"main": "lib/main.js",
"version": "0.11.5",
"version": "0.11.6",
"ignore": [
"**/.*",
"node_modules",
Expand Down
111 changes: 67 additions & 44 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
* @property {string} [contextMenuItemBorderRadius=3px] - Override value for contextMenuItemBorderRadius.
* @property {string} [contextMenuLabelDisplay=inline-block] - Override value for contextMenuLabelDisplay.
* @property {string} [contextMenuLabelMinWidth=75px] - Override value for contextMenuLabelMinWidth.
* @property {string} [contextMenuLabelMaxWidth=150px] - Override value for contextMenuLabelMaxWidth.
* @property {string} [contextMenuLabelMaxWidth=700px] - Override value for contextMenuLabelMaxWidth.
* @property {string} [contextMenuHoverBackground=rgba(182, 205, 250, 1)] - Override value for contextMenuHoverBackground.
* @property {string} [contextMenuColor=rgba(43, 48, 43, 1)] - Override value for contextMenuColor.
* @property {string} [contextMenuHoverColor=rgba(43, 48, 153, 1)] - Override value for contextMenuHoverColor.
Expand Down Expand Up @@ -603,7 +603,7 @@
['clearSettingsOptionText', 'Clear saved settings'],
['showOrderByOptionTextAsc', 'Order by %s ascending'],
['showOrderByOptionTextDesc', 'Order by %s descending'],
['removeFilterOptionText', 'Unfilter %s'],
['removeFilterOptionText', 'Remove filter on %s'],
['filterOptionText', 'Filter']
],
defaultStyles = [
Expand Down Expand Up @@ -638,9 +638,10 @@
['styleSheet', ''],
['contextMenuItemMargin', '2px'],
['contextMenuItemBorderRadius', '3px'],
['contextMenuLabelMargin', '0 3px 0 0'],
['contextMenuLabelDisplay', 'inline-block'],
['contextMenuLabelMinWidth', '75px'],
['contextMenuLabelMaxWidth', '150px'],
['contextMenuLabelMaxWidth', '700px'],
['contextMenuHoverBackground', 'rgba(182, 205, 250, 1)'],
['contextMenuColor', 'rgba(43, 48, 43, 1)'],
['contextMenuHoverColor', 'rgba(43, 48, 153, 1)'],
Expand Down Expand Up @@ -738,11 +739,7 @@
['reorderMarkerBorderColor', 'rgba(0, 0, 0, 0.2)'],
['reorderMarkerBorderWidth', 1.25],
['gridBorderColor', 'rgba(202, 202, 202, 1)'],
['gridBorderWidth', 1],
['truncateWhiteSpace', 'nowrap'],
['truncateOverflow', 'hidden'],
['truncateTextOverflow', 'ellipsis'],
['truncateVerticalAlign', 'bottom']
['gridBorderWidth', 1]
],
orders = {
rows: [],
Expand Down Expand Up @@ -1007,6 +1004,16 @@
}
return f;
}
function getBestGuessDataType(columnName) {
var t, x, l = data.length;
for (x = 0; x < l; x += 1) {
if ([null, undefined].indexOf(data[x][columnName]) !== -1) {
t = typeof data[x];
return t === 'object' ? 'string' : t;
}
}
return 'string';
}
/**
* Returns an auto generated schema based on data structure.
* @memberof canvasDataGrid#
Expand All @@ -1016,7 +1023,7 @@
*/
function getSchemaFromData() {
return Object.keys(data[0] || {' ': ''}).map(function mapEachSchemaColumn(key, index) {
var type = typeof data[0][key],
var type = getBestGuessDataType(key),
i = {
name: key,
title: key,
Expand Down Expand Up @@ -1738,7 +1745,7 @@
&& activeCell.rowIndex === r) {
ctx.lineWidth = style.activeCellOverlayBorderWidth;
ctx.strokeStyle = style.activeCellOverlayBorderColor;
strokeRect(headerCellWidth, y, getHeaderWidth(), rowHeight);
strokeRect(0, y, getHeaderWidth(), rowHeight);
}
y += cellHeight + borderWidth;
return true;
Expand Down Expand Up @@ -2230,15 +2237,32 @@
- new Date(a[columnName]).getTime();
};
};
/**
* Checks if a cell is currently visible.
* @memberof canvasDataGrid#
* @method
* @returns {boolean} when true, the cell is visible, when false the cell is not currently drawn.
* @param {cell} cell The cell to check for. Alternatively you can pass an object { x: <x-index>, y: <y-index> }.
*/
function isCellVisible(cell) {
var x, l = visibleCells.length;
for (x = 0; x < l; x += 1) {
if (cell.x === visibleCells[x].x && cell.y === visibleCells[x].y) {
return true;
}
}
return false;
}
/**
* Sets the order of the data.
* @memberof canvasDataGrid#
* @method
* @returns {cell} cell at the selected location.
* @param {number} columnName Number of pixels from the left.
* @param {string} direction `asc` for ascending or `desc` for descending.
* @param {bool} dontSetStorageData Don't store this setting for future use.
*/
function order(columnName, direction) {
function order(columnName, direction, dontSetStorageData) {
var f,
c = getSchema().filter(function (col) {
return col.name === columnName;
Expand All @@ -2251,9 +2275,10 @@
if (!f && c[0].type !== undefined) {
console.warn('Cannot sort type "%s" falling back to string sort.', c[0].type);
}
data = data.sort(f(columnName, direction) || sorters.string);
data = data.sort(typeof f === 'function' ? f(columnName, direction) : sorters.string);
dispatchEvent('ordercolumn', [columnName, direction], intf);
draw(true);
if (dontSetStorageData) { return; }
setStorageData();
}
function isInGrid(e) {
Expand Down Expand Up @@ -2473,24 +2498,11 @@
|| dragStartObject.columnIndex !== o.columnIndex) {
ignoreNextClick = true;
}
if ((!selectionBounds || (dragBounds.top !== selectionBounds.top
|| dragBounds.left !== selectionBounds.left
|| dragBounds.bottom !== selectionBounds.bottom
|| dragBounds.right !== selectionBounds.right)) && !ctrl) {
selections = [];
sBounds = dragBounds;
selectArea(sBounds, true);
if (attributes.rowSelectionMode) {
for (i = selectionBounds.top; i <= selectionBounds.bottom; i += 1) {
selectRow(i, true, true);
}
}
}
if (cellBoundaryCrossed || (delta.x === 0 && delta.y === 0)) {
if (cellBoundaryCrossed || (delta.x === 0 && delta.y === 0) || attributes.rowSelectionMode) {
if (attributes.rowSelectionMode || dragStartObject.columnIndex === -1) {
selectRow(o.rowIndex, ctrl, true);
} else {
if (!dragAddToSelection) {
if (!dragAddToSelection && o.rowIndex) {
if (selections[o.rowIndex] && selections[o.rowIndex].indexOf(o.columnIndex) !== -1) {
selections[o.rowIndex].splice(selections[o.rowIndex].indexOf(o.columnIndex), 1);
}
Expand All @@ -2502,6 +2514,20 @@
}
}
}
if ((!selectionBounds || (dragBounds.top !== selectionBounds.top
|| dragBounds.left !== selectionBounds.left
|| dragBounds.bottom !== selectionBounds.bottom
|| dragBounds.right !== selectionBounds.right)) && !ctrl) {
selections = [];
sBounds = dragBounds;
if (attributes.rowSelectionMode) {
for (i = sBounds.top; i <= sBounds.bottom; i += 1) {
selectRow(i, true, true);
}
} else {
selectArea(sBounds, true);
}
}
autoScrollZone(e, x, y, ctrl);
}
}
Expand Down Expand Up @@ -2571,15 +2597,13 @@
* @param {string} value The value to filter for.
*/
function setFilter(column, value) {
if (!columnFilters && !column && !value) {
refreshFromOrigialData();
}
data = originalData;
refreshFromOrigialData();
// if we receive an empty value for a filter, delete it
if (column && value === '') {
if (column && (value === '' || value === undefined)) {
delete columnFilters[column];
} else {
columnFilters[column] = value;
}
columnFilters[column] = value;
Object.keys(columnFilters).forEach(function (filter) {
var header = getHeaderByName(column);
if (!header) {
Expand Down Expand Up @@ -2619,7 +2643,7 @@
columnFilter = columnFilters[contextObject.header.name] || '';
filterContainer = document.createElement('div');
filterLabel = document.createElement('div');
filterLabel.className = 'canvas-datagrid-context-menu-label truncate-text';
filterLabel.className = 'canvas-datagrid-context-menu-label';
filterInput = document.createElement('input');
filterLabel.innerHTML = attributes.filterOptionText + ' ' + contextObject.header.name;
filterContainer.appendChild(filterLabel);
Expand Down Expand Up @@ -3637,16 +3661,11 @@
margin: style.contextMenuItemMargin
},
'canvas-datagrid-context-menu-label': {
'margin': style.contextMenuLabelMargin,
display: style.contextMenuLabelDisplay,
'min-width': style.contextMenuLabelMinWidth,
'max-width': style.contextMenuLabelMaxWidth,
},
'truncate-text': {
'white-space': style.truncateWhiteSpace,
overflow: style.truncateOverflow,
'text-overflow': style.truncateTextOverflow,
'vertical-align': style.truncateVerticalAlign
},
'canvas-datagrid-context-menu': {
'font-family': style.contextMenuFontFamily,
'font-size': style.contextMenuFontSize,
Expand Down Expand Up @@ -3845,10 +3864,6 @@
if (storedSettings && typeof storedSettings.orders === 'object') {
if (storedSettings.orders.rows.length >= data.length) {
orders.rows = storedSettings.orders.rows;
orderBy = storedSettings.orderBy === undefined
? uniqueId : storedSettings.orderBy;
orderDirection = storedSettings.orderDirection === undefined
? uniqueId : storedSettings.orderDirection;
}
s = getSchema();
orders.columns = storedSettings.orders.columns;
Expand All @@ -3857,6 +3872,13 @@
orders.columns.push(i);
}
});
orderBy = storedSettings.orderBy === undefined
? uniqueId : storedSettings.orderBy;
orderDirection = storedSettings.orderDirection === undefined
? uniqueId : storedSettings.orderDirection;
if (getHeaderByName(orderBy) && orderDirection) {
order(orderBy, orderDirection);
}
}
}
function init() {
Expand Down Expand Up @@ -3886,6 +3908,7 @@
intf.findColumnMaxTextLength = findColumnMaxTextLength;
intf.disposeContextMenu = disposeContextMenu;
intf.getCellAt = getCellAt;
intf.isCellVisible = isCellVisible;
intf.order = order;
intf.draw = draw;
intf.selectArea = selectArea;
Expand Down
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "canvas-datagrid",
"version": "0.11.5",
"version": "0.11.6",
"description": "Canvas based data grid",
"main": "./lib/main.js",
"repository": {
Expand All @@ -19,6 +19,17 @@
"spreadsheet"
],
"author": "Tony Germaneri <[email protected]>",
"contributors": [
{
"url": "https://github.com/TonyGermaneri/canvas-datagrid/graphs/contributors"
}
],
"maintainers": [
{
"name": "Tony Germaneri",
"email": "[email protected]"
}
],
"license": "BSD-3-Clause",
"bugs": {
"url": "https://github.com/TonyGermaneri/canvas-datagrid/issues"
Expand Down
34 changes: 18 additions & 16 deletions tutorials/sample.js

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

0 comments on commit 2e81a34

Please sign in to comment.