Skip to content

Commit

Permalink
added null check, updated readme, fixed stupid function name
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Germaneri committed Dec 1, 2016
1 parent 7bf653c commit c381793
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
33 changes: 25 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ Simple creation and data set.

Attributes
==========

Attributes can be set during instantiation or after
by accessing `grid.attributes`. If changed after instantiation some attributes
require calling `grid.draw()` to see changes.
Attributes can be set during instantiation or after by accessing `grid.attributes`.
Changing an attribute will automatically call `draw`.

showNewRow: true
----------------
Expand Down Expand Up @@ -87,7 +85,6 @@ allowRowResize: true
----------------
When true, the user can resize the row headers increasing the height of the row.


allowRowResizeFromCell: false
----------------
When true, the user can resize the height of the row from the border of the cell.
Expand Down Expand Up @@ -120,6 +117,12 @@ When true, row headers are shown.

Properties
==========
The difference between attributes and properties is that attributes
are always getter/setters that can be passed during instantiation and
that call `draw` and describe behaviors while properties are references
to internal objects and function maps like `filters`. You can change
the sub-properties of the various properties, but the base property
is immutable.

changes
-------
Expand Down Expand Up @@ -178,6 +181,7 @@ the style default.
style
-----
Object that contains the properties listed in the style section.
Changing a style will automatically call `draw`.

resizeMode
----------
Expand Down Expand Up @@ -251,6 +255,8 @@ Each column object can have the following properties:
| formatter | The formatter function used display this column. If no function is provided, type will determine formatter.|
| defaultValue | The default value of this column for new rows. This is a function that takes the arguments `header` and `index` and must return a value for new default cells in this column.|

Example schema:

[
{
name: 'col1'
Expand All @@ -264,7 +270,7 @@ Each column object can have the following properties:
]

Methods
==========
=======

beginEditAt(x, y)
-----------------
Expand All @@ -288,11 +294,11 @@ scrollIntoView(x, y)
--------------------
Scrolls the cell at cell x, row y into view if it is not already.

gotoToCell(x, y)
gotoCell(x, y)
------------------
Scrolls to the cell at cell x, row y.

gotoToRow(y)
gotoRow(y)
------------
Scrolls to the row y.

Expand Down Expand Up @@ -352,6 +358,13 @@ Sets the value of the filter.
Events
======

Events are subscribed to using `addEventListener` and unsubscribed from using `removeEventListener`.
Some events have a first argument with the method `preventDefault`. Calling `preventDefault` will
prevent the default behavior from occurring. For example, if you wanted to prevent the edit cell
from appearing for some cells you can subscribe to the `beforebeginedit` event and call `e.preventDefault`
when you want the cell to be read only. Using events will give you the most granular control of appearance
and behavior.

selectionchanged
----------------
Fires when the selection changes.
Expand Down Expand Up @@ -672,6 +685,10 @@ This object is returned by a number of events, methods and properties, and is pa

Styles
==========
Styles can be passed during instantiation or after.
Changing a style will automatically call `draw`.

grid.style.cellBackgroundColor = 'burlywood';

| Property | Default Value |
|-----|------|
Expand Down
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.9.4",
"version": "0.9.5",
"ignore": [
"**/.*",
"node_modules",
Expand Down
13 changes: 7 additions & 6 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ define([], function context() {
});
}
function addEllipsis(text, width) {
if (typeof text !== 'string') { return ''; }
var o = text, i = text.length;
while (width < ctx.measureText(o).width && i > 1) {
i -= 1;
Expand Down Expand Up @@ -940,16 +941,16 @@ define([], function context() {
}
return left;
}
function gotoToCell(x, y) {
function gotoCell(x, y) {
if (x !== undefined) {
scrollBox.scrollLeft = findColumnScrollLeft(x);
}
if (y !== undefined) {
scrollBox.scrollTop = findRowScrollTop(y);
}
}
function gotoToRow(y) {
gotoToCell(0, y);
function gotoRow(y) {
gotoCell(0, y);
}
function scrollIntoView(x, y) {
if (visibleCells.filter(function (cell) {
Expand All @@ -960,7 +961,7 @@ define([], function context() {
&& cell.x + cell.width < container.offsetWidth
&& cell.y + cell.height < container.offsetHeight;
}).length === 0) {
gotoToCell(x, y);
gotoCell(x, y);
}
}
function setActiveCell(x, y) {
Expand Down Expand Up @@ -1432,8 +1433,8 @@ define([], function context() {
intf.setActiveCell = setActiveCell;
intf.scrollIntoView = scrollIntoView;
intf.clearChangeLog = clearChangeLog;
intf.gotoToCell = gotoToCell;
intf.gotoToRow = gotoToRow;
intf.gotoCell = gotoCell;
intf.gotoRow = gotoRow;
intf.findColumnScrollLeft = findColumnScrollLeft;
intf.findRowScrollTop = findRowScrollTop;
intf.fitColumnToValues = fitColumnToValues;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "canvas-datagrid",
"version": "0.9.4",
"version": "0.9.5",
"description": "Canvas based data grid",
"main": "./lib/main.js",
"scripts": {
Expand Down

0 comments on commit c381793

Please sign in to comment.