Gathering detailed insights and metrics for grid
Gathering detailed insights and metrics for grid
Gathering detailed insights and metrics for grid
Gathering detailed insights and metrics for grid
npm install grid
Typescript
Module System
Min. Node Version
Node Version
NPM Version
79.8
Supply Chain
93
Quality
77.3
Maintenance
100
Vulnerability
100
License
JavaScript (51.66%)
TypeScript (46.7%)
SCSS (1.02%)
HTML (0.56%)
Dockerfile (0.06%)
Total Downloads
122,725
Last Day
203
Last Week
1,814
Last Month
3,614
Last Year
24,485
28 Stars
733 Commits
9 Forks
125 Watching
27 Branches
9 Contributors
Latest Version
4.10.8
Package Id
grid@4.10.8
Unpacked Size
1.93 MB
Size
709.98 kB
File Count
219
NPM Version
6.14.13
Node Version
12.18.3
Cumulative downloads
Total Downloads
Last day
-51.1%
203
Compared to previous day
Last week
103.6%
1,814
Compared to previous week
Last month
159.4%
3,614
Compared to previous month
Last year
24.7%
24,485
Compared to previous year
8
50
A highly scalable grid component written in javscript DEMO
Note: while Grid is fully functional it is still in beta. Use at your own risk and please file any issues on GitHub.
Also the grid is currently packaged for use with browserify. If you need a build for a non browserify (or webpack) environment please open an issue on github.
npm install --save grid
To run the sample app locally, run npm start
and hit http://localhost:8082
var core = require('grid')
var grid = core();
The grid handles most complexity for you. There are only three user supplied requirements to a get a grid up and running
Row and column descriptors are objects that tell the grid how wide or high to make your cells. They also control things like whether or not a column is hidden and describe the overall dimensions of the grid.
1 // add some columns 2 var colDescriptors = []; 3 var colDescriptor; 4 for (var c = 0; c < 20; c++) { 5 // create a col descriptor 6 colDescriptor = grid.colModel.create(); 7 colDescriptor.width = 78; 8 colDescriptor.hidden = !!(c % 2); // hide every other column for fun and profit 9 } 10 grid.colModel.add(colDescriptors); 11 12 // add some rows 13 var rowDescriptors = []; 14 var rowDescriptor; 15 for (var r = 0; r < 20; r++) { 16 // create a row descriptor 17 rowDescriptor = grid.rowModel.create(); 18 rowDescriptor.height = 24; 19 if(r === 0){ 20 rowDescriptor.header = true; 21 } 22 } 23 grid.rowModel.add(rowDescriptors);
The grid determines what to render for a given cell by calling the supplied data model. This gives the client massive flexbility to generate and return the data however they need to.
The datamodel can be a simple object that the user sets on the grid instance dataModel
field and needs to implement at a minimum
get
, getHeader
, and isDirty
,
if you support user data entry and want paste to work you should also implement set
Here's a basic read only implementation:
1// use the grid's default dirty clean implementation almost always 2// (it will automatically be set clean on each draw by the grid) 3var dataDirtyClean = grid.makeDirtyClean(); 4 5grid.dataModel = { 6 7 get: function(dataRowIndex, dataColIndex, isCopy) { 8 var rawValue = [dataRowIndex, dataColIndex]; 9 return { 10 value: rawValue, 11 formatted: 'r' + rawValue[0] + ', c' + rawValue[1] 12 }; 13 }, 14 15 getHeader: function(headerRowIndex, headerColIndex) { 16 var rawValue = [headerRowIndex, headerColIndex]; 17 return { 18 value: rawValue, 19 formatted: 'hr' + rawValue[0] + ', hc' + rawValue[1] 20 }; 21 }, 22 23 isDirty: dataDirtyClean.isDirty 24};
Finally we just need to tell the grid to set itself up in a container of our choosing:
1var container = document.createElement('div'); 2container.style.width = '800px'; 3container.style.height = '800px'; 4document.body.appendChild(container); 5grid.build(container);
Many of the apis in the grid utilize two concepts when referencing coordinates: spaces and units. It's good to understand these before using the more advanced features.
Coordinates in the grid exist in one of three spaces.
virtual - represents all of the data in your grid including the headers. for example, if you have a grid with one header row, then (0, 20)
in the 'virtual'
space references the column 20 of the header. (1, 20)
would reference column 20 of the first data row.
data - very similar to virtual but does not include the headers. so (0,20)
references the first row of data at the 20th column and technically (-1, 20)
would represent the 20th column in the header although negative indexes are rarely used
view - the view space represents the actual dom nodes that are rendered for the grid's virtualization. the grid's implementation renders enough cells to fill the entire viewport and no more (usually around 20-30 rows and 10 cols depending on sizes). in this space (0,20)
would reference the dom cell at column 20 of the first row. even if you scroll the grid it will always point at that cell, so a view coordinate can be translated to different virtual coordinates depending on the scroll. you could think of view coordinates as a correlary for position: fixed
in css
Units in the grid are straightforward. They are either
px - pixels, so (0,0)
in the view space is the very top left pixel of the grid no matter the scroll, whereas (0,0)
in the virtual space is the top left pixel only when the grid hasn't been scrolled, and would technically refer to a pixel out of view if the grid has been scrolled
or
cell - cells, so (0,0)
in the view space represents the top left cell regardless of scroll, and (0,0)
in the virtual space would represent an off screen cell if scrolled and top left if not scrolled
There are two ways to get non text (read html) into a grid:
Decorators are great for adding a piece of one-off ui that doesn't relate directly to the content of a cell or doesn't need to be in every row of a column or vice versa. For example, the grid internally uses decorators to render the focus and selection highlight as well as resize handles.
basic decorator
1 var top = 1, 2 left = 2, 3 height = 1, 4 width = 1, 5 unit = 'cell', 6 space = 'view'; 7 var d = grid.decorators.create(top, left, height, width, unit, space); 8 9 // return some element 10 d.render = function() { 11 var a = document.createElement('a') 12 a.textContent = 'link Text!' 13 return a; 14 }; 15 grid.decorators.add(d);
Puts a link over the cell at row 1 col 2 that doesn’t move with the scroll (why you would do this is questionable but it's just an example).
You can do more complicated things like render directives: (requires grid-angular-adapter)
angular directive decorator
1angular.module('myCoolGrid', [require('grid')]) 2 3 .controller('MyGridCtrl', function($scope, GridSrvc, GridDecoratorSrvc) { 4 var grid = GridSrvc.core(); 5 6 // do row col and datamodel setup... 7 8 var top = 20, 9 left = 10, 10 height = 2, 11 width = 2, 12 unit = 'cell', 13 space = 'virtual'; 14 var d = grid.decorators.create(top, left, height, width, unit, space); 15 16 // return some element 17 d.render = function() { 18 var scope = $scope.$new(); 19 scope.interestingData = 'INTERESTING DATA!!!'; 20 return GridDecoratorSrvc.render({ 21 $scope: scope, 22 template: '<my-directive data="interestingData"></my-directive>', 23 events: true 24 }); 25 }; 26 grid.decorators.add(d); 27 });
This will put your compiled directive in a box that spans from row 20-22
and col 10-12
, and moves appropriately with the scroll. The events
flag lets the grid know that this decorator is interactable and should receive mouse events. (Otherwise pointer events are set to none.) The GridDecoratorSrvc takes care of destroying the scope and properly removing elements to avoid memory leaks with angular. You definitely should use it for any angular decorators.
Builders help you to get html into the actual cells of a given row or column instead of the text that would have been rendered.
basic builders
1var builder = grid.colModel.createBuilder(function render() { 2 return angular.element('<a href="#"></a>')[0]; 3}, function update(elem, ctx) { 4 grid.viewLayer.setTextContent(elem, ctx.data.formatted); 5 return elem; 6}); 7var colDescriptor = grid.colModel.create(builder);
have <a>
tags in your cells for all the rows in that column
Note: it's important for the update function of a builder to be extremely fast. Call scope.$digest
not scope.$apply
, and use grid.viewLayer.setTextContent
not elem.innerHTML
where possible
If you want to update the look and feel of the grid, here are a few classes that you can override to give you the look you want.
.grid-cell
:
This class is responsible for the look of individual cells.
.grid-focus-decorator
: This decorator class is applied when you click('focus') on a cell
Ex. Adding the following style will give you a cell with a blue border around it when the cell is selected.
1.grid-focus-decorator { 2 border: 2px solid blue; 3}
.grid-selection
:
When selecting rows and columns, this class sets the border and background so you know which rows you are exactly selecting
Ex.
1$grid-teal: #39CCCC !default; 2.grid-selection { 3 border: 1px solid $grid-teal; 4 background: transparentize($grid-teal, .8); 5}
.grid-row
:
This class is responsible for the look of the row of cells.
Ex. To apply, a background color when hovering over each row, add the following:
1.grid-row { 2 &.hover { 3 background-color: lighten($grid-teal, 30) !important; 4 } 5}
To apply styles only to the header row, use the following class:
1.grid-row { 2 &.grid-is-header { 3 } 4} 5
.col-resize
: This class changes the look of the column resizing element.
.grid-drag-line
: This class is used when you are resizing a column. A vertical line is added to guide you of how much to resize your columns.
Ex. To show a blue vertical line when resizing a column, add the following
1.grid-drag-line { 2 background: #7FDBFF; 3}
No vulnerabilities found.
No security vulnerabilities found.