I am trying to display a set of stored results from aurelia-store when a user clicks on the Search link.
In order to make sure the document is loaded first, I have done the following:
constructor()
{
this.loadResults = e => {
console.log('loaded', this.state.searchObj);
this.activate();
};
}
attached()
{
document.addEventListener('aurelia-composed', () => {
this.loadResults();
});
}
then further down, I am doing the following to get the document and load the results:
var eGridDiv = document.querySelector('#resultsGrid');
var newDiv;
//console.log('document', document);
//console.log('egriddiv', eGridDiv);
if (typeof(eGridDiv) == undefined || eGridDiv == null)
{
newDiv = document.createElement('div');
newDiv.id = 'resultsGrid';
newDiv.classList.add('ag-theme-alpine');
newDiv.style.height = '300px';
newDiv.style.width = '1200px';
var bodyDiv = document.getElementById('pagecontent');
console.log('bodyDiv', bodyDiv);
//bodyDiv.appendChild(newDiv);
document.body.appendChild(newDiv);
eGridDiv = document.querySelector('#resultsGrid');
console.log('2 egriddiv', eGridDiv);
this.resultsGrid = new ag.Grid(eGridDiv, this.resultsGridOptions);
if (typeof(this.state) != undefined && this.state != null)
{
this.results = this.state.searchObj.results;
}
this.resultsGridOptions.api.setRowData(this.state.searchObj.results);
this.resultsGridOptions.api.refreshCells();
}
else
{
this.resultsGrid = new ag.Grid(eGridDiv, this.resultsGridOptions);
this.resultsGridOptions.api.setRowData(this.state.searchObj.results);
this.resultsGridOptions.api.refreshCells();
}
The attached()
fires the first time the page is loaded, but when I click away from it to a view of a customer, and then click the link again, it does not fire attached(), which means the document is not loaded, and then it creates the new div, and then attaches it right to the body. Which means that the search form is underneath the search results.
What am I missing in this?
Thanks