EasyUI Forum
April 19, 2024, 08:54:03 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: SideMenu default selection  (Read 7564 times)
chrwei
Full Member
***
Posts: 219


View Profile Email
« on: November 01, 2019, 10:30:07 AM »

there doesn't seem to be a way set a default selection, or to programatically select an item.  am I overlooking it?

what I'm looking to do is to sync the menu with Router, so when you go directly to a path it is selected in the SideMenu
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: November 05, 2019, 12:43:11 AM »

Please update to the newest version and set the 'selection' property for the SideMenu component.
Logged
chrwei
Full Member
***
Posts: 219


View Profile Email
« Reply #2 on: November 06, 2019, 11:19:27 AM »

this, based on your "AppLayout" example, doesn't seem to be working, what am I missing?

Code:
import React from 'react';
import { SideMenu } from 'rc-easyui';
 
class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      title: 'AppLayout',
      width: 200,
      collapsed: false,
      selectedMenu: { text: "Wizard" },
      menus: [
        {
          text: "Forms",
          iconCls: "fa fa-wpforms",
          state: "open",
          children: [
            {
              text: "Form Element"
            },
            {
              text: "Wizard"
            },
            {
              text: "File Upload"
            }
          ]
        },
        {
          text: "Mail",
          iconCls: "fa fa-at",
          selected: true,
          children: [
            {
              text: "Inbox"
            },
            {
              text: "Sent"
            },
            {
              text: "Trash",
              children: [
                {
                  text: "Item1"
                },
                {
                  text: "Item2"
                }
              ]
            }
          ]
        },
        {
          text: "Layout",
          iconCls: "fa fa-table",
          children: [
            {
              text: "Panel"
            },
            {
              text: "Accordion"
            },
            {
              text: "Tabs"
            }
          ]
        }
      ]
    }
  }
  toggle() {
    const { collapsed } = this.state;
    this.setState({
      collapsed: !collapsed,
      width: collapsed ? 200 : 50
    })
  }
  handleItemClick(item) {
    this.setState({ selectedMenu: item })
  }
  render() {
    const { menus, title, width, selectedMenu, collapsed } = this.state;
    return (
      <div>
        <div className="f-column">
          <div className="main-header f-row">
            <div className="f-row f-full">
              <div className="main-title f-animate f-row" style={{ width: width }}>
                <img className="app-logo" src="https://www.jeasyui.com/favicon.ico" />
                {!collapsed && <span>{title}</span>}
              </div>
              <div className="main-bar f-full">
                <span className="main-toggle fa fa-bars" onClick={this.toggle.bind(this)}></span>
              </div>
            </div>
          </div>
          <div className="f-row f-full">
            <div className="sidebar-body f-animate" style={{ width: width }}>
              {!collapsed && <div className="sidebar-user">User Panel</div>}
              <SideMenu
                data={menus} border={false} collapsed={collapsed}
                onItemClick={this.handleItemClick.bind(this)}
                selected={selectedMenu}
                ></SideMenu>
            </div>
            <div className="main-body f-full">
              {selectedMenu && <p>{selectedMenu.text}</p>}
            </div>
          </div>
        </div>
      </div>
    );
  }
}
 
export default App;
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #3 on: November 06, 2019, 07:01:58 PM »

Please follow these steps.

1. Import the 'treeHelper' to find the specified node in menus.
Code:
import { SideMenu, treeHelper } from 'rc-easyui';

2. Set the 'selectedMenu' property value.
Code:
class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      title: 'AppLayout',
      width: 200,
      collapsed: false,
      selectedMenu: treeHelper.findNode(menus, 'text', 'Wizard'),
      menus: menus
    }
  }
...

3. Set the 'selection' instead of the 'selected'.
Code:
<SideMenu
  data={menus}
  border={false}
  collapsed={collapsed}
  onItemClick={this.handleItemClick.bind(this)}
  selection={selectedMenu}
/>
Logged
chrwei
Full Member
***
Posts: 219


View Profile Email
« Reply #4 on: November 18, 2019, 02:38:37 PM »

got it working, thanks.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!