I have a requirement where I use jQuery Treetable in Lightning and I have implemented the same as below code. I created a Lightning Tab from this component and used in Lightning Experience.
Component:
<aura:component implements="force:appHostable">
<ltng:require scripts="/resource/treeTable/treeTableJS.js" afterScriptsLoaded="{!c.loadScripts}"/>
<aura:attribute name="temp" type="String" default="none" />
<aura:attribute name="content" type="String[]" default="item1,item2,item3,item4" />
<table id="table">
<tbody>
<tr data-tt-id="parent">
<td><ui:button label="Click" press="{!c.selectClick}" /></td>
<td>Content</td>
</tr>
<aura:iteration items="{!v.content}" var="item" indexVar="index">
<tr data-tt-id="{!'child'+index}" data-tt-parent-id="parent">
<td></td>
<td>{!item}</td>
</tr>
</aura:iteration>
</tbody>
</table>
</aura:component>
Controller:
({
loadScripts : function(component, event, helper) {
$("#table").treetable({
expandable: true
}, {
force: true
}, {
initialState: "collapsed"
});
},
selectClick : function(component, event, helper) {
if(component.get("v.temp")==="none"){
component.set("v.temp","plus");
$("#table").treetable("expandNode", "parent");
} else{
component.set("v.temp","none");
$("#table").treetable("collapseNode", "parent");
}
},
})
Now about the issue, when I use this in Lightning tab first time it works (meaning straight forward scenario), but now from this page I navigate to any standard record page (be it Accounts record page) or even Home page and come back to this lightning tab, it does not work. We have to refresh the page to make it work again. Any resolve so that we don't need to refresh the page? Please help. Note: Lightning Locker service is disabled.