MegaMenuMegaMenu displays submenus of root items together.

MegaMenu - 图1

Documentation

Import

  1. import {MegaMenuModule} from 'primeng/megamenu';
  2.  

MenuModel API

MegaMenu uses the common menumodel api to define its items, visit MenuModel API for details.

Getting Started

MegaMenu requires nested menuitems as its model where the items of a root menuitem is a two dimensional array to define columns in an overlay submenu.

  1. <p-megaMenu [model]="items"></p-megaMenu>
  2.  
  1. export class MegaMenuDemo {
  2. items: MenuItem[];
  3. ngOnInit() {
  4. this.items = [
  5. {
  6. label: 'TV', icon: 'fa fa-fw fa-check',
  7. items: [
  8. [
  9. {
  10. label: 'TV 1',
  11. items: [{label: 'TV 1.1'},{label: 'TV 1.2'}]
  12. },
  13. {
  14. label: 'TV 2',
  15. items: [{label: 'TV 2.1'},{label: 'TV 2.2'}]
  16. }
  17. ],
  18. [
  19. {
  20. label: 'TV 3',
  21. items: [{label: 'TV 3.1'},{label: 'TV 3.2'}]
  22. },
  23. {
  24. label: 'TV 4',
  25. items: [{label: 'TV 4.1'},{label: 'TV 4.2'}]
  26. }
  27. ]
  28. ]
  29. },
  30. {
  31. label: 'Sports', icon: 'fa fa-fw fa-soccer-ball-o',
  32. items: [
  33. [
  34. {
  35. label: 'Sports 1',
  36. items: [{label: 'Sports 1.1'},{label: 'Sports 1.2'}]
  37. },
  38. {
  39. label: 'Sports 2',
  40. items: [{label: 'Sports 2.1'},{label: 'Sports 2.2'}]
  41. },
  42. ],
  43. [
  44. {
  45. label: 'Sports 3',
  46. items: [{label: 'Sports 3.1'},{label: 'Sports 3.2'}]
  47. },
  48. {
  49. label: 'Sports 4',
  50. items: [{label: 'Sports 4.1'},{label: 'Sports 4.2'}]
  51. }
  52. ],
  53. [
  54. {
  55. label: 'Sports 5',
  56. items: [{label: 'Sports 5.1'},{label: 'Sports 5.2'}]
  57. },
  58. {
  59. label: 'Sports 6',
  60. items: [{label: 'Sports 6.1'},{label: 'Sports 6.2'}]
  61. }
  62. ]
  63. ]
  64. }
  65. ];
  66. }
  67. }
  68.  

Custom Content

Custom content can be placed between p-megaMenu tags. Megamenu should be horizontal for custom content.

  1. <p-megaMenu [model]="items">
  2. <input type="text" pInputText placeholder="Search">
  3. <button pButton label="Logout" icon="fa fa-sign-out"></button>
  4. </p-megaMenu>
  5.  

Properties

NameTypeDefaultDescription
modelarraynullAn array of menuitems.
orientationstringhorizontalDefines the orientation, valid values are horizontal and vertical.
stylestringnullInline style of the component.
styleClassstringnullStyle class of the component.
baseZIndexnumber0Base zIndex value to use in layering.
autoZIndexbooleantrueWhether to automatically manage layering.

Styling

Following is the list of structural style classes, for theming classes visit theming page.

NameElement
ui-megamenuContainer element.
ui-menu-listList element.
ui-menuitemMenuitem element.
ui-menuitem-textLabel of a menuitem.
ui-menuitem-iconIcon of a menuitem.
ui-submenu-iconArrow icon of a submenu.

Dependencies

None.

Source

View on GitHub

  1. <p-megaMenu [model]="items"></p-megaMenu>
  2.  
  1. export class MegaMenuDemo {
  2. items: MenuItem[];
  3. ngOnInit() {
  4. this.items = [
  5. {
  6. label: 'TV', icon: 'fa fa-fw fa-check',
  7. items: [
  8. [
  9. {
  10. label: 'TV 1',
  11. items: [{label: 'TV 1.1'},{label: 'TV 1.2'}]
  12. },
  13. {
  14. label: 'TV 2',
  15. items: [{label: 'TV 2.1'},{label: 'TV 2.2'}]
  16. }
  17. ],
  18. [
  19. {
  20. label: 'TV 3',
  21. items: [{label: 'TV 3.1'},{label: 'TV 3.2'}]
  22. },
  23. {
  24. label: 'TV 4',
  25. items: [{label: 'TV 4.1'},{label: 'TV 4.2'}]
  26. }
  27. ]
  28. ]
  29. },
  30. {
  31. label: 'Sports', icon: 'fa fa-fw fa-soccer-ball-o',
  32. items: [
  33. [
  34. {
  35. label: 'Sports 1',
  36. items: [{label: 'Sports 1.1'},{label: 'Sports 1.2'}]
  37. },
  38. {
  39. label: 'Sports 2',
  40. items: [{label: 'Sports 2.1'},{label: 'Sports 2.2'}]
  41. },
  42. ],
  43. [
  44. {
  45. label: 'Sports 3',
  46. items: [{label: 'Sports 3.1'},{label: 'Sports 3.2'}]
  47. },
  48. {
  49. label: 'Sports 4',
  50. items: [{label: 'Sports 4.1'},{label: 'Sports 4.2'}]
  51. }
  52. ],
  53. [
  54. {
  55. label: 'Sports 5',
  56. items: [{label: 'Sports 5.1'},{label: 'Sports 5.2'}]
  57. },
  58. {
  59. label: 'Sports 6',
  60. items: [{label: 'Sports 6.1'},{label: 'Sports 6.2'}]
  61. }
  62. ]
  63. ]
  64. },
  65. {
  66. label: 'Entertainment', icon: 'fa fa-fw fa-child',
  67. items: [
  68. [
  69. {
  70. label: 'Entertainment 1',
  71. items: [{label: 'Entertainment 1.1'},{label: 'Entertainment 1.2'}]
  72. },
  73. {
  74. label: 'Entertainment 2',
  75. items: [{label: 'Entertainment 2.1'},{label: 'Entertainment 2.2'}]
  76. }
  77. ],
  78. [
  79. {
  80. label: 'Entertainment 3',
  81. items: [{label: 'Entertainment 3.1'},{label: 'Entertainment 3.2'}]
  82. },
  83. {
  84. label: 'Entertainment 4',
  85. items: [{label: 'Entertainment 4.1'},{label: 'Entertainment 4.2'}]
  86. }
  87. ]
  88. ]
  89. },
  90. {
  91. label: 'Technology', icon: 'fa fa-fw fa-gears',
  92. items: [
  93. [
  94. {
  95. label: 'Technology 1',
  96. items: [{label: 'Technology 1.1'},{label: 'Technology 1.2'}]
  97. },
  98. {
  99. label: 'Technology 2',
  100. items: [{label: 'Technology 2.1'},{label: 'Technology 2.2'}]
  101. },
  102. {
  103. label: 'Technology 3',
  104. items: [{label: 'Technology 3.1'},{label: 'Technology 3.2'}]
  105. }
  106. ],
  107. [
  108. {
  109. label: 'Technology 4',
  110. items: [{label: 'Technology 4.1'},{label: 'Technology 4.2'}]
  111. }
  112. ]
  113. ]
  114. }
  115. ];
  116. }
  117. }
  118.