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
AdminLTE3 - how to fix active sidebar #2068
Comments
Hello @jvbalcita Can you test this, please: /** add active class and stay opened when selected */
var url = window.location;
// for sidebar menu entirely but not cover treeview
$('ul.nav-sidebar a').filter(function() {
return this.href == url;
}).addClass('active');
// for treeview
$('ul.nav-treeview a').filter(function() {
return this.href == url;
}).parentsUntil(".nav-sidebar > .nav-treeview").addClass('menu-open').prev('a').addClass('active'); |
it's working @arbex10 . Thank you very much! |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
You should place it bottom on your master layout HTML page or whatever the HTML page you're trying to have the ADMIN LTE Sidebar. just open a simple <script></script> tag and put the code in there. |
el código va dentro de un script en el pie de pagina antes de finalizar así: /** add active class and stay opened when selected */
var url = window.location;
// for sidebar menu entirely but not cover treeview
$('ul.nav-sidebar a').filter(function() {
return this.href == url;
}).addClass('active');
// for treeview
$('ul.nav-treeview a').filter(function() {
return this.href == url;
}).parentsUntil(".nav-sidebar > .nav-treeview").addClass('menu-open').prev('a').addClass('active'); |
This comment has been minimized.
This comment has been minimized.
@arbexmb when blog/users this works but blog/users/3/edit for this url not working for menuopen |
It only works for the first element of second level, could you help me to work with the rest of levels? |
放到基础模板或者每个页面的前面。 $(document).ready(function() {
/** add active class and stay opened when selected */
var url = window.location;
// for sidebar menu entirely but not cover treeview
$('ul.nav-sidebar a').filter(function() {
return this.href == url;
}).addClass('active');
// for treeview
$('ul.nav-treeview a').filter(function() {
return this.href == url;
}).parentsUntil(".nav-sidebar > .nav-treeview").addClass('menu-open').prev('a').addClass('active');
}) 你这典型的中式英语,茫茫多的英语中一眼就能看出来是国人! |
I searched too many documentation but @arbexmb code is working perfectly! Thank you!! |
I'm using rails 6 with $(document).on("turbolinks:load", function() {
var url = window.location
$("ul.nav-sidebar a").filter(toggleNavSidebar);
$("ul.nav-treeview a").filter(toggleNavTreeview);
function toggleNavSidebar() {
if (this.href != url) return
$(this).addClass("active")
}
function toggleNavTreeview() {
if (this.href != url) return
$(this).parentsUntil(".nav-sidebar > .nav-treeview")
.addClass("menu-open").prev("a").addClass("active");
}
}) |
I found a solution similar to the one mentioned: `
` |
thank you it's ver helpful |
This code should be placed in adminlte.js. |
Environment:
In the previous version of AdminLTE which is the Bootstrap 3 there is a fix to make the sidebar dynamically active when selected.
Here's the code used
but now in AdminLTE 3 this code is not working.
Is anyone already tried this? and produced a resolution?
Thanks in advance
The text was updated successfully, but these errors were encountered: