Code Monkey home page Code Monkey logo

lightning-data-grid's Introduction

Deploy Deploy to Salesforce

Lightning-Data-Grid No Maintenance Intended

A data grid for the Lightning Component Framework

screenshot of lightning data grid

You probably do not need this. The lightning:datatable and lightning:treegrid(Coming in Spring '18!) base components probably fulfill your use case, and you should look at those components first. However, if your use case for a data grid is not fulfilled by either of those two base components, Lightning-Data-Grid might be the answer. This component is intended as an extensible and low-level data grid that can be built up into more usable components. Currently supports inline-editing of hierarchical data , virtual scrolling, and global search. This is still a huge WIP, use as your own risk.

Quick Demo Setup

  1. Click on Deploy to SFDX button.
  2. Navigate to a page you want to add the data grid component.
  3. Add in the DataGridImpl component to a page layout.

About

The Data Grid contains a toolbar component, a header component (right now this just renders the column names, in the future it can contain filtering/column menus), a row component, and a cell component.

The Data Grid currently has a pretty simple API, it expects a config javascript object, and a data javascript object.

The config should look like:

{
  columns: [
      {
          name: "columnName that matches the name of the dataField",
          label: "Label string that is displayed for the column header"
      }
  ],
  rowsDisplayed: *Integer*,
  scrollable: *boolean*,
  editable: *boolean*
}

columns: Column definition of the data grid. Requires name and label for rendering. Any properties you set here will get populated down to the cell decorators and cell editors.

rowsDisplayed: How many rows are initially rendered. Control how big the table is!

scrollable: Enables virtual scrolling on desktop.

editable: You can control whether the entire grid is editable. Columns also take an editable flag, so you can control it ast the column level as well.

The data object currently takes the following shape:

{
    data: {
        id: "dataId",
        name: "dataName"
        etc . . . These keys should match your column names, and is how the data in the row will get displayed
    },
    parent: null
}

Right now I am trying to keep the actual record data separate from some of the row properties needed for displaying hierarchies and such. This way you only have to extract the data object out of the row data, instead of doing a bunch of property deleting, which is always fun.

Explanation of other properties:

parent: id of the parent row for a child row. In the future, I would like to be able to determine this via configuration, and specify a parent field within the data object.

Decorators and Editors implement the cellFacet interface. Check out the defaultDecorator, defaultEditor, programmaticDecorator, and programmaticEditor for examples. The two default use aura:if for their implementation, while the two programmatic components perform their logic with a javascript controller and $A.createComponent. They get fed the cell value and the associated column data. The general idea is to conditionally render a component based on that information.

You can look at the DefaultSearch component to see how a global search for the grid is being implemented, and how you could change it to implement your own search. The GetAttribute event can be used to get any attribute off of the grid, and takes a callback that can be invoked with that value. The DefaultSearch uses this get the grid data, but it can be used for other use cases outside of this. It then filters out the matches it wants, and sends a GridViewMutation event, which sets the current grid view. The plan is to use this event for sorting and filtering as well.

Look at DataGridImpl component for an example of all of this being setup.

Methods

Init: Once you have the data for the Grid, you can call the init method on it, and the grid will take care of setting everything up and rendering the view. Refresh: Call refresh on the grid when you change the data structure.

lightning-data-grid's People

Contributors

madmax983 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lightning-data-grid's Issues

Row Selection

As a user I want to select a row (or multiple rows), and then hit a button and have some sort of action performed on the row selected.

This should be controlled as a config value on the grid that determines whether the grid is single row selectable, multi-row selectable, or not selectable at all.

Failures

Deployment Started
Status: Queued
Status: InProgress
Status: Completed
Deployment Complete
Failures:
package.xml(jasmineReporter):An object 'jasmineReporter' of type StaticResource was named in package.xml, but was not found in zipped directory
package.xml(jasmine):An object 'jasmine' of type StaticResource was named in package.xml, but was not found in zipped directory
package.xml(exampleData2):An object 'exampleData2' of type StaticResource was named in package.xml, but was not found in zipped directory
package.xml(Tests):An object 'Tests' of type AuraDefinitionBundle was named in package.xml, but was not found in zipped directory
package.xml(testutil):An object 'testutil' of type StaticResource was named in package.xml, but was not found in zipped directory
package.xml(lodash):An object 'lodash' of type StaticResource was named in package.xml, but was not found in zipped directory
package.xml(lightningDataGridTests):An object 'lightningDataGridTests' of type StaticResource was named in package.xml, but was not found in zipped directory
package.xml(jasmineboot):An object 'jasmineboot' of type StaticResource was named in package.xml, but was not found in zipped directory
package.xml(BaseTestRunnerCmp):An object 'BaseTestRunnerCmp' of type AuraDefinitionBundle was named in package.xml, but was not found in zipped directory

Pagination

As a implementer of this grid, I would like to decide whether I have virtual scrolling or pagination. There are use cases where pagination is a better UX.

We already have rowsDisplayed and the dataset, so should be relatively easy to extrapolate the number of pages and set up pagination.

Firefox support

Degraded functionality in Firefox:

  1. Virtual scrolling doesn't work.
  2. When attempting to mouse scroll, the hover events are still being disabled, so this results in all clickable elements on the grid being disabled.

Chevron reverts to unexpanded when scrolling

I caught this is in sanity testing after the re-work for sfdx. We are keeping track of the state of the hierarchy in the hierarchy attribute now so that child rows get proper virtualization. The expanded state of the child row is properly being kept track of when a row instantiates, but the chevron isn't respecting this.

Weird lightning:buttonIcon issue

New issue that has cropped up:

If you toggle a child row, then scroll down and scroll back up, the grid is maintaining the state of the hierarchy as expected. However, the lightning:buttonIcon for chevron right and chevron down get rendered rotated 90 degrees.

This is just cropping up in Winter '18.

Child Row Templates

Currently, child rows render with the same columns as the rest of the grid, which works great for homogeneous hierarchies (ex. Parent Account and Children Accounts).

Need the ability to render a different set of columns for children rows so heterogeneous hierarchies can be represented (ex. Account and Contact).

Persisting Edits

I suppose this is a flavor of an Enhancement Request, but I'm curious if you had thoughts around how a "Save" button would work here. My first thought is to loop through the rowDatas and look for dirty, but the way it's stored key'd by columnName, it seems like a lot of effort to loop through every column name on every row to check for a dirty flag. I haven't done any performance tests with that yet, so it's entirely possible that it's not a factor; even at large data volumes, but my instinct is that it would be slow.

I'm going to try a few things along that route, but I thought I'd float this for discussion.

Another thought involves using some sort of dataProviderComponent that is wired into each cell (row maybe?), and has direct access to shared dataStore (via the window? --- similar to your redux store component setup). I suppose it would also be possible to leave the store at the table level and communicate changes by events, but my experience in the framework gives me a bad feeling about that. (Speed wise, and falling into the nightmare of keeping attributes/data in sync between multiple components.)

Scrolling Improvements

Problems with the current infinite scrolling implementation:

  1. Performance is okay, but not great. I want it to be great. Taking notes from React-Virtualized, as that has nice set of optimizations that should theoretically carry over.

  2. Using mousewheel event works nice on desktop, but is obviously right out on mobile/Salesforce1. Could bind on mousetouch as well, but is exhibits real stutter without doing some improvements. Right now I am using the Load More button, but that is broken with the latest changes.

Config option for Tree

Right now even if a grid has no hierarchy, the grid will run its algos to determine the children structure. Should provide a config to avoid that and have a perf improvement when using the grid for non-tree situations.

Search

A configurable global search in the toolbar.

AuraDoc

Make an auradoc, and get some examples running to use with the new Component Reference Suite.

Eliminate Aura:If in Cell

Eliminate the aura:if used in the cell component. Over a large set of data this will have a big performance impact.

Draggable Columns

A configuration option should enable users to drag and resort columns.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.