Skip to content

Commit

Permalink
Refresh (#44)
Browse files Browse the repository at this point in the history
* #43 Data grid now handles data refresh
  • Loading branch information
madmax983 committed Jan 30, 2018
1 parent 51bad53 commit de6ff48
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
4 changes: 2 additions & 2 deletions force-app/main/default/aura/DataGrid/DataGrid.cmp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
<aura:attribute name="offSetIndex"
access="public"
type="integer"
description="The index of the current data offset"
default="0"/>
description="The index of the current data offset"/>
<aura:attribute name="title" type="Aura.Component[]" access="global"/>
<aura:attribute name="toolbarButtons" type="Aura.Component[]" access="global"/>
<aura:attribute name="toolbarBody" type="Aura.Component[]" access="global"/>
Expand All @@ -46,6 +45,7 @@

<!-- Methods -->
<aura:method name="init" action="{!c.dataGridInit}"/>
<aura:method name="refresh" action="{!c.refresh}"/>

<!-- Handlers -->
<aura:handler name="childToggle"
Expand Down
4 changes: 4 additions & 0 deletions force-app/main/default/aura/DataGrid/DataGridController.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
component.set("v.initFired", true)
}
},
refresh: function(component, event, helper) {
helper.toggleSpinner(component);
component.init();
},
lodashLoaded: function(component) {
component.set("v.lodashLoaded", true);
var initFired = component.get("v.initFired");
Expand Down
17 changes: 9 additions & 8 deletions force-app/main/default/aura/DataGrid/DataGridHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@
treeInit: function(component) {
var config = component.get("v.config"), scrollable = config.scrollable;
var data = component.get("v.data"),
offSetIndex = component.get("v.offSetIndex"),
displaySize = component.get("v.config.rowsDisplayed")
? component.get("v.config.rowsDisplayed")
: 20,
offSetIndex = component.get("v.offSetIndex") ? component.get("v.offSetIndex") : displaySize,
self = this;

var promises = self.getRootNodes(data);
Expand All @@ -88,14 +88,14 @@
var mChildren = component.mChildren.entries();
component.mChildren = new Map([...component.mChildren, ...value]);
});

var offSetData = parents.slice(offSetIndex, displaySize);
var rangeStart = offSetIndex - displaySize;
var offSetData = parents.slice(rangeStart, offSetIndex);
self.setHasChildren(offSetData, component.mChildren);

self.toggleSpinner(component);
component.set("v.hierarchy", parents);
component.set("v.view", offSetData);
component.set("v.offSetIndex", displaySize);
component.set("v.offSetIndex", rangeStart + displaySize);
});
});
if(scrollable) {
Expand All @@ -105,16 +105,17 @@
gridInit: function(component) {
var config = component.get("v.config"), scrollable = config.scrollable;
var data = component.get("v.data"),
offSetIndex = component.get("v.offSetIndex"),
displaySize = component.get("v.config.rowsDisplayed")
? component.get("v.config.rowsDisplayed")
: 20;
: 20,
offSetIndex = component.get("v.offSetIndex") ? component.get("v.offSetIndex") : displaySize;

this.toggleSpinner(component);
var offSetData = data.slice(offSetIndex, displaySize);
var rangeStart = offSetIndex - displaySize;
var offSetData = data.slice(rangeStart, offSetIndex);
component.set("v.hierarchy", data);
component.set("v.view", offSetData);
component.set("v.offSetIndex", displaySize);
component.set("v.offSetIndex", rangeStart + displaySize);

if(scrollable) {
component.mouseWheelHandler = this.mouseWheelHandler("v.hierarchy", component);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,22 @@ describe("Grid Tests", function() {
});
});

it('handles a data refresh', function(done) {
return $T.waitFor(function() {
var grid = cmp.find("exampleGrid");
return grid.get("v.view").length > 0;
}).then(function(){
var grid = cmp.find("exampleGrid");
var data = grid.get("v.data");
data[0].data.name = "Captain Hook";
grid.set("v.data", data);
grid.refresh();
var view = grid.get("v.view");
expect(view[0].data.name).toBe("Captain Hook");
done();
});
});

it('handles a cell edit', function(done) {
return $T.waitFor(function() {
var grid = cmp.find("exampleGrid");
Expand Down

0 comments on commit de6ff48

Please sign in to comment.