New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sidebar menu treeview not working after redirection in Angular 4 #1570
Comments
Hi i have same problem in using vue2. |
I replaced // $(window).on('load', function () { |
Hello @mb00110101, i had the same problem in a Angular 4 application. In my case, i have the loginPage When i reload the homePage, everything is ok. In my analysis i see that adminlte.js file initializes treeview plugin in the ngOnInit() {
$(document).ready(() => {
const trees: any = $('[data-widget="tree"]');
trees.tree();
});
} and, of course my treeview in HTML has the attribute <ul class="sidebar-menu" data-widget="tree">
<li class="header">Menu</li>
<li class="treeview link-pointer" routerLinkActive="active menu-open">
<a>
<i class="fa fa-linux"></i> <span>Item</span>
<span class="pull-right-container">
<i class="fa fa-angle-left pull-right"></i>
</span>
</a>
<ul class="treeview-menu">
<li class="" routerLinkActive="active"><a [routerLink]="['/main']"><i class="fa fa-linux"></i> Sub Item</a></li>
</ul>
</li>
</ul> I hope it can help you. |
Thanks, I can close this issue. |
Hi, |
Hello @thiagoreis, your HTML and TSC looks like mine? ngOnInit() {
$(document).ready(() => {
const trees: any = $('[data-widget="tree"]');
trees.tree();
});
} in the component that has the HTML properties. What version of AdminLTE you're using? |
Thanks @mateusduraes!
|
Thank you! Your solution works and the sidebar turns normal. |
This problem in Angular 6 and AdminLTE 3 was solved as follows: Note: I have a Sidebar component that contains the treeview. Import jquery and AdminLTE import * as $ from 'jquery';
import * as AdminLte from 'admin-lte'; ... In ngAfterViewInit() {
$('[data-widget="treeview"]').each(function() {
AdminLte.Treeview._jQueryInterface.call($(this), 'init');
});
} I do not know if this is the best solution, but it worked. |
I tried @mateusduraes solution but I can't seem to get it to work. It always tells me that trees() is not a function. I included all the styles and scripts as @thiagoreis suggested. When trying @viniciuslj suggestion I get the error that _jQueryInterface can't be found. Any idea? |
I got it working. You have to make sure to install and import jquery-ui-dist. More Information on the topic: https://stackoverflow.com/questions/45512475/angular4-cant-find-jquery-ui-functions |
Hi @mateusduraes , thanks for sharing your source code with us. It worked for me. But now i have another problem that maybe you can help me with. I try to implement dynamically generated tree menu. I'm about to finish it but i have an annoying problem which took my hours. Tree menu nodes which have childs keep opened when they should be closed/collapsed after i click another nodes in the tree menu. There is also an open issue here but i'm not sure if my code is correct. I also tried it on your code but it produces the same unwanted result. Have you ever tried to create three/multi level menu? |
@mb00110101 I facing same issue after redirection from login page to dashboard page, left side bar tree menu not working. I am not using Angular template of Admin LTE. I have used latest bootstrap Admin LTE template to Angular 7 project. I added required css and scripts files in assets folder. Please let me know how this issue can resolve. I tried solution of @XpamAmAdEuS and @mateusduraes But its still not working for me. |
z-index |
worked for me thanks..
this solution solved my problem |
I facing same issue after redirection from login page to dashboard page, left side bar tree menu not working. |
how to do it in admin lte 3 |
You got it? |
Hello, I faced the same problem on AdminLTE 3 with React. This is how I solved it. Create a JavaScript file with the content below :
const $ = window.$;
export function loadTree() {
And on the react component which contains the menu items invoke this function inside componentDidMount()
import { loadTree } from "./js/MenuTreeHelper.js";
|
Thank you dnzbrkyrk it's work correctly |
For anyone who is struggling with this. I'm using AdminLTE 3.0 with React. Same situation, redirecting user from Login to Dashboard. useEffect(() => { or you can set in componentDidMount() if you are using class-based component. Spend 2 days investigating this. Hope it helps. |
@mh7777777 |
Make sure you add it on top level component where your children or JSX from that component contain Sidebar menu and all of these features from Dashboard. useEffect will be called after everything is rendered. With that said, that's the right moment when this snippet of code needs to run because everything is in DOM right now.
|
Edit: I missed it before, but now saw the Thanks for the explanation, it is much appreciated.
|
I suspect something is off with my project; I either keep getting Are jQuery and admin-lte required to be devDependencies or regular dependencies? Any tips on how you correctly insert jQuery would be greatly appreciated, and if you have a guess as to why the Treeview function isn't present (though I understand that might be a tough guess without knowing the project). |
Thank you brother, it worked here for me. I'm using angular 8.0.3 and admin lte 3.0.5 |
I believe it is a problem of the circle of life, as @mateusduraes said. The solution proposed by @viniciuslj worked fine with me, in my case i are using vuejs.
Sorry for the mistakes in my english, I'm learning. |
this really worked for me thanks a lot. one other thing make sure you call useEffect in the component which has the navbar HTML or has the data-widget otherwise calling it in another component wont work unless the component with the widget is in the rendered component tree. |
It worked for me but now the topbar toggle button to hide the sidebar is not working, any idea? |
Thank you very much, it worked for me. Using AdminLTE 3.2 and Angular 12 |
In React js if i reload on some other page and come back to the sidebar-menu page the sidebar menu stops working then i have to reload the page again ,then the side bar menu treeview works. can someone please help me on this , Thank you |
I have de same problem. Open the menu but cannot close. |
Hello, to those who cannot close the treeview is due to it is init more than once. One possible solution import * as $ from 'jquery';
export function loadTreeview() {
$('[data-widget="treeview"]').each(function () {
if ($(this).data('treeview-init') === undefined) {
$(this).Treeview('init');
$(this).data('treeview-init', true);
}
});
} |
Thanks! This worked for me! |
Hi,
I'm using AdminLTE theme (2.4.0-rc) in Angular4 project. Dashboard with the sidebar menu is on url "http://host/". When I enter this address in browser address field, everything is working correct.
Problem is when app is on other url, i.e. "http://host/login" and there is link to main page or redirection in code used one of methods:
this.router.navigateByUrl('/')
or<a routerLink="/">
.After redirection to the Dashboard by one of these methods, sidebar menu "treeview" option does not open. Therefore after redirection by
<a href="/">
everything works correct. There isn't any errors in dev console. It seems like some AdminLTE js function not see "treeview" element after redirection by Angular 4 methods. Is it any solution to make Angular 4 works as expected?The text was updated successfully, but these errors were encountered: