Angular Ribbon Component

The Ribbon component for Angular represents a widget which can be used as a tabbed toolbar or mega menu.

1. Installation

The easiest way to get started with jQWidgets UI for Angular is to use the Angular CLI Tool. To scaffold your project structure, follow its installation instructions.

npm install -g @angular/cli
ng new jqwidgets-project
cd jqwidgets-project

Install jQWidgets

jQWidgets Angular UI comes packaged with Angular CLI schematics to make creating Angular applications easier. Schematics are included with both @angular/cdk and jqwidgets-ng. Once you install the npm packages, they will be available through the Angular CLI.

Angular CLI supports the addition of packages through the ng add command. The ng add command provides faster and more user-friendly package installation. To install the jQWidgets UI for Angular package, use ng add and add the name of the NPM package:

ng add jqwidgets-ng

Alternatively, you can use the standard installation (Manual Setup)

jQWidgets UI for Angular is distributed as jqwidgets-ng NPM package

  1. Download and install the package.
    npm install jqwidgets-ng
  2. Adding CSS reference

    The following CSS file is available in ../node_modules/jqwidgets-ng/ package folder. This can be referenced in [src/styles.css] using following code.

    @import 'jqwidgets-ng/jqwidgets/styles/jqx.base.css';

    Another way to achieve the same is to edit the angular.json file and in the styles add the style.

    "styles": [
    	"node_modules/jqwidgets-ng/jqwidgets/styles/jqx.base.css"
    ]
    

2. Add the HTML for jQWidgets component in src/app/app.component.html

app.component.html


<jqxRibbon #ribbonReference
           [width]="getWidth()" [height]="131" [animationType]="'none'"
           [selectionMode]="'click'" [position]="'top'" [mode]="'default'"
           [theme]="'demoTheme'" [selectedIndex]="1">
  <ul>
    <li id="fileItem">
      <jqxDropDownButton id='fileItemButton' #fileItemButton
                         [width]="50" [height]="26" [arrowSize]="0"
                         [dropDownWidth]="120" [theme]="'demoTheme'">
        <div style="height:110px;">
          <ul style="list-style-type: none; margin:0px; padding: 3px;">
            <li>
              <jqxButton class='button' [theme]="'demoTheme'">
                <div class="icon SaveImage"></div> Save
              </jqxButton>
            </li>
            <li>
              <jqxButton class='button' [theme]="'demoTheme'">
                <div class="icon SaveSelectionImage"></div> Save As
              </jqxButton>
            </li>
            <li>
              <jqxButton class='button' [theme]="'demoTheme'">
                <div class="icon folder"></div> Open
              </jqxButton>
            </li>
            <li>
              <jqxButton class='button' [theme]="'demoTheme'">
                <div class="icon close"></div> Close
              </jqxButton>
            </li>
          </ul>
        </div>
      </jqxDropDownButton>
    </li>
    <li>Home</li>
    <li>Help</li>
  </ul>
  <div>
    <div style="overflow: hidden;">
    </div>
    <div style="overflow: hidden;">
      <table class="buttonHolderTable" id="clipBoardTable">
        <tr>
          <td rowspan="3" style="text-align: center; height: 70px; font-size: 10px">
            <div id="paste" style="width: 50px;">
              <jqxButton #pasteButton (onClick)='onPasteButtonClick($event)' (mousedown)='onMouseDownPasteButton($event)'
                         [width]="35" [height]="56" [theme]="'demoTheme'">
                <span class="icon page_paste" style="zoom: 1.5"></span><span class="pasteText">Paste</span>
              </jqxButton>
              <jqxDropDownList (onSelect)='onPasteDropDownSelect($event)'
                               [width]="22" [height]="10" [autoDropDownHeight]="true" [animationType]="'none'"
                               [theme]="" [selectedIndex]="0" [source]="pasteData" [dropDownWidth]="110"
                               [renderer]="pasteRenderer" [selectionRenderer]="pasteRelectionRenderer">
              </jqxDropDownList>
            </div>
          </td>
          <td class="firstrow" rowspan="1">
            <jqxTooltip [position]="'mouse'" [theme]="'demoTheme'" [content]="'Cut (Ctrl + X)'">
              <jqxButton id='cutButton' #cutButton [theme]="'demoTheme'">
                <div class="icon cut_red"></div>
                <span class="cutText">Cut</span>
              </jqxButton>
            </jqxTooltip>
          </td>
        </tr>
        <tr>
          <td class="secondrow">
            <jqxTooltip [position]="'mouse'" [theme]="'demoTheme'" [content]="'Copy (Ctrl + C)'">
              <jqxButton id='copyButton' #copyButton>
                <div class="icon page_copy"></div>
                <span class="copyText">Copy</span>
              </jqxButton>
            </jqxTooltip>
          </td>
        </tr>
        <tr>
          <td class="thirdrow">
            <jqxTooltip [position]="'mouse'" [theme]="'demoTheme'" [content]="'Format Painter'">
              <jqxButton id='formatPainter' #formatPainter [theme]="'demoTheme'">
                <div class="icon FormatPainterImage"></div>
                <span class="formatPainter">Format Painter</span>
              </jqxButton>
            </jqxTooltip>
          </td>
        </tr>
        <tr>
          <td colspan="2" style="font-size: 9px; text-align: center; top: -3px; position: relative;">
            Clipboard
          </td>
        </tr>
      </table>
      <div class="sectionSeparator">
      </div>
      <table class="buttonHolderTable" style="float: left;">
        <tr>
          <td colspan="4">
            <jqxDropDownList [width]="120" [height]="21" [autoDropDownHeight]="true"
                             [theme]="'demoTheme'" [selectedIndex]="1" [source]="fontListSource">
            </jqxDropDownList>
          </td>
          <td>
            <jqxDropDownList [width]="70" [height]="21" [autoDropDownHeight]="true" [renderer]="fontSizeListRenderer"
                             [theme]="'demoTheme'" [selectedIndex]="2" [source]="fontSizeListSource">
            </jqxDropDownList>
          </td>
          <td>
            <jqxButton [theme]="'demoTheme'"><div class="icon fontsizeincrease16"></div></jqxButton>
          </td>
          <td>
            <jqxButton [theme]="'demoTheme'"><div class="icon fontsizedecrease16"></div></jqxButton>
          </td>
          <td>
            <jqxButton [theme]="'demoTheme'"><div class="icon ClearFormattingImage"></div></jqxButton>
          </td>
          <td>
            <jqxDropDownList [width]="40" [selectionRenderer]="changeCaseListSelectionRenderer" [autoDropDownHeight]="true"
                             [theme]="'demoTheme'" [selectedIndex]="0" [source]="changeCaseListSource" [dropDownWidth]="150">
            </jqxDropDownList>
          </td>
        </tr>
        <tr class="secondrow">
          <td colspan="8">
            <jqxDropDownButton #fontColor
                               [width]="130" [height]="21"
                               [dropDownWidth]="180" [theme]="'demoTheme'">
              <div style="padding: 3px;">
                <jqxColorPicker (onColorchange)='onFontColorPicker($event)'
                                [width]="180" [height]="180"
                                [color]="'FF0000'" [colorMode]="'hue'">
                </jqxColorPicker>
              </div>
            </jqxDropDownButton>
            <div class="separator"></div>
            <jqxDropDownButton #highlightColor
                               [width]="130" [height]="21"
                               [dropDownWidth]="180" [theme]="'demoTheme'">
              <div style="padding: 3px;">
                <jqxColorPicker (onColorchange)='onHighlightColorPicker($event)'
                                [width]="180" [height]="180"
                                [color]="'FF0000'" [colorMode]="'hue'">
                </jqxColorPicker>
              </div>
            </jqxDropDownButton>
          </td>
        </tr>
        <tr class="thirdrow">
          <td colspan="8" style="padding: 0;">
            <jqxTooltip [position]="'mouse'" [theme]="'demoTheme'" [content]="'Superscript'" [height]="20">
              <jqxToggleButton #superscript (onClick)='onSuperScriptClick()' [theme]="'demoTheme'">
                <div class="icon text_superscript"></div>
              </jqxToggleButton>
            </jqxTooltip>
            <jqxTooltip [position]="'mouse'" [theme]="'demoTheme'" [content]="'Subscript'" [height]="20">
              <jqxToggleButton #subscript (onClick)='onSubScriptClick()' [theme]="'demoTheme'">
                <div class="icon text_subscript"></div>
              </jqxToggleButton>
            </jqxTooltip>
            <div class="separator" style="top: 3px;"></div>
            <jqxTooltip [position]="'mouse'" [theme]="'demoTheme'" [content]="'Bold (Ctrl + B)'" [height]="20">
              <jqxToggleButton [theme]="'demoTheme'">
                <div class="icon text_bold"></div>
              </jqxToggleButton>
            </jqxTooltip>
            <jqxTooltip [position]="'mouse'" [theme]="'demoTheme'" [content]="'Italic (Ctrl + I)'" [height]="20">
              <jqxToggleButton [theme]="'demoTheme'">
                <div class="icon text_italic"></div>
              </jqxToggleButton>
            </jqxTooltip>
            <jqxTooltip [position]="'mouse'" [theme]="'demoTheme'" [content]="'Underline (Ctrl + U)'" [height]="20">
              <jqxToggleButton [theme]="'demoTheme'">
                <div class="icon text_underline"></div>
              </jqxToggleButton>
            </jqxTooltip>
            <jqxTooltip [position]="'mouse'" [theme]="'demoTheme'" [content]="'Strikethrough'" [height]="20">
              <jqxToggleButton [theme]="'demoTheme'">
                <div class="icon text_strikethrough"></div>
              </jqxToggleButton>
            </jqxTooltip>
          </td>
        </tr>
        <tr>
          <td colspan="9" style="height: 10px; font-size: 9px; text-align: center;">
            Font
          </td>
        </tr>
      </table>
      <div class="sectionSeparator">
      </div>
      <table class="buttonHolderTable" style="float: left; margin-top: -4px">
        <tr class="firstrow">
          <td colspan="8">
            <jqxTooltip [position]="'mouse'" [theme]="'demoTheme'" [content]="'Bulleted List'">
              <jqxButton [theme]="'demoTheme'">
                <div class="icon text_list_bullets"></div>
              </jqxButton>
            </jqxTooltip>
            <jqxTooltip [position]="'mouse'" [theme]="'demoTheme'" [content]="'Numbered List'">
              <jqxButton [theme]="'demoTheme'">
                <div class="icon text_list_numbers"></div>
              </jqxButton>
            </jqxTooltip>
            <jqxTooltip [position]="'mouse'" [theme]="'demoTheme'" [content]="'Decrease Indent'">
              <jqxButton [theme]="'demoTheme'">
                <div class="icon text_indent"></div>
              </jqxButton>
            </jqxTooltip>
            <jqxTooltip [position]="'mouse'" [theme]="'demoTheme'" [content]="'Increase Indent'">
              <jqxButton [theme]="'demoTheme'">
                <div class="icon text_indent_remove"></div>
              </jqxButton>
            </jqxTooltip>
            <jqxTooltip [position]="'mouse'" [theme]="'demoTheme'" [content]="'Sort Direction'">
              <jqxButton [theme]="'demoTheme'">
                <div class="icon SortHS"></div>
              </jqxButton>
            </jqxTooltip>
            <jqxTooltip [position]="'mouse'" [theme]="'demoTheme'" [content]="'Fill Style'">
              <jqxDropDownButton #bucketColor
                                 [width]="42" [height]="19"
                                 [dropDownWidth]="180" [theme]="'demoTheme'">
                <div style="padding: 3px;">
                  <jqxColorPicker (onColorchange)='onBucketColorPicker($event)'
                                  [width]="180" [height]="180"
                                  [color]="'000000'" [colorMode]="'hue'">
                  </jqxColorPicker>
                </div>
              </jqxDropDownButton>
            </jqxTooltip>
          </td>
        </tr>
        <tr class="secondrow">
          <td colspan="8">
            <jqxTooltip [position]="'mouse'" [theme]="'demoTheme'" [content]="'Align Text Left (Ctrl + L)'">
              <jqxButton [theme]="'demoTheme'">
                <div class="icon text_align_left"></div>
              </jqxButton>
            </jqxTooltip>
            <jqxTooltip [position]="'mouse'" [theme]="'demoTheme'" [content]="'Center (Ctrl + E)'">
              <jqxButton [theme]="'demoTheme'">
                <div class="icon text_align_center"></div>
              </jqxButton>
            </jqxTooltip>
            <jqxTooltip [position]="'mouse'" [theme]="'demoTheme'" [content]="'Align Text Right (Ctrl + R)'">
              <jqxButton [theme]="'demoTheme'">
                <div class="icon text_align_right"></div>
              </jqxButton>
            </jqxTooltip>
            <jqxTooltip [position]="'mouse'" [theme]="'demoTheme'" [content]="'Justify (Ctrl + J)'">
              <jqxButton [theme]="'demoTheme'">
                <div class="icon text_align_justify"></div>
              </jqxButton>
            </jqxTooltip>
            <div class="separator" style="top:5px; height: 15px;"></div>
            <jqxTooltip [position]="'mouse'" [theme]="'demoTheme'" [content]="'Line and Paragraph Spacing'">
              <jqxButton [theme]="'demoTheme'">
                <div class="icon text_linespacing"></div>
              </jqxButton>
            </jqxTooltip>
            <jqxTooltip [position]="'mouse'" [theme]="'demoTheme'" [content]="'Show/Hide special characters'">
              <jqxButton [theme]="'demoTheme'">
                <div class="icon ShowParagraphMarksImage"></div>
              </jqxButton>
            </jqxTooltip>
          </td>
        </tr>
        <tr>
          <td style="height: 35px; text-align: center; vertical-align: bottom; font-size: 9px;">
            Alignment
          </td>
        </tr>
      </table>
      <div class="sectionSeparator">
      </div>
    </div>
    <div style="overflow: hidden;">
      <table class="buttonHolderTable" style="height: 100%;">
        <tr>
          <td class="bigTd">
            <jqxButton class='button left' [theme]="'demoTheme'" [width]="36" [height]="36">
              <img class="img" src="./../../../../images/help-26.png" />
            </jqxButton>
            Help
          </td>
          <td class="bigTd">
            <jqxButton class='button left' [theme]="'demoTheme'" [width]="36" [height]="36">
              <img class="img" src="./../../../../images/about-26.png" />
            </jqxButton>
            About
          </td>
          <td class="bigTd">
            <jqxButton class="button left" [theme]="'demoTheme'" [width]="36" [height]="36">
              <img class="img" src="./../../../../images/downloading_updates-26.png" />
            </jqxButton>
            Update
          </td>
        </tr>
      </table>
    </div>
  </div>
</jqxRibbon>
<jqxGrid [width]="800" [source]="gridData.source" [theme]="'demoTheme'" [editable]="true"
         [columnsresize]="true" [selectionmode]='"multiplecellsadvanced"' [columns]="gridData.columns">
</jqxGrid>	

3. Setup Component Logic

app.component.ts


import { Component, ViewChild, ViewEncapsulation } from '@angular/core';

import { jqxButtonComponent, jqxButtonModule } from 'jqwidgets-ng/jqxbuttons';
import { jqxTooltipComponent, jqxTooltipModule } from 'jqwidgets-ng/jqxtooltip';
import { jqxDropDownButtonComponent, jqxDropDownButtonModule } from 'jqwidgets-ng/jqxdropdownbutton';
import { jqxColorPickerComponent, jqxColorPickerModule } from 'jqwidgets-ng/jqxcolorpicker';
import { jqxDropDownListComponent, jqxDropDownListModule } from 'jqwidgets-ng/jqxdropdownlist';
import { jqxToggleButtonComponent, jqxToggleButtonModule } from 'jqwidgets-ng/jqxtogglebutton';

import { jqxRibbonModule, jqxRibbonComponent } from 'jqwidgets-ng/jqxribbon';
import { jqxGridModule, jqxGridComponent } from 'jqwidgets-ng/jqxgrid';

@Component({
    selector: 'app-root',
    imports: [jqxRibbonModule, jqxGridModule, jqxButtonModule, jqxTooltipModule, jqxDropDownButtonModule, jqxColorPickerModule, jqxToggleButtonModule, jqxDropDownListModule],
    standalone: true,
    styleUrls: ['./app.component.css'],
    templateUrl: './app.component.html',
    encapsulation: ViewEncapsulation.None
})

export class AppComponent {
    @ViewChild('ribbonReference') ribbon: jqxRibbonComponent;
    @ViewChild('fileItemButton') fileItemButton: jqxDropDownButtonComponent;
    @ViewChild('bucketColor') bucketColorButton: jqxDropDownButtonComponent;
    @ViewChild('fontColor') fontColorButton: jqxDropDownButtonComponent;
    @ViewChild('highlightColor') highlightColorButton: jqxDropDownButtonComponent;
    @ViewChild('pasteButton') pasteButton: jqxButtonComponent;
    @ViewChild('superscript') superScriptToggleButton: jqxToggleButtonComponent;
    @ViewChild('subscript') subscriptToggleButton: jqxToggleButtonComponent;

    getWidth(): any {
        if (document.body.offsetWidth < 800) {
            return '90%';
        }

        return 800;
    }

    ngAfterViewInit(): void {
        this.buttonsStyling();
        this.ribbon.elementRef.nativeElement.firstElementChild.children[1].style.padding = '35px 0px 0px';
        this.ribbon.disableAt(0);
        this.fileItemButton.setContent('<span style="position: relative; line-height: 26px; margin-left:10px;">File</span>');
        this.fontColorButton.setContent('<span style="position: relative; display:inline; top: 2px"><div class="icon FontDialogImage"></div><span id="fontColorPreview" style="display: block; position:absolute;  height: 3px; width: 16px; background:#000"></span></span><span style="position:relative; display: inline; top:3px">Font Color</span>');
        this.bucketColorButton.setContent('<span style="position: relative; display:inline"><div class="icon paintcan"></div><span id="bucketColorPreview" style="display: block; position:absolute;  height: 3px; width: 16px; background:#000"></span></span><span style="position:relative; display: inline; top:3px"></span>');
        this.highlightColorButton.setContent('<span style="position: relative; display:inline; top: 2px"><div class="icon pencil"></div><span id="highlightColorPreview" style="display: block; position:absolute;  height: 3px; width: 16px; background:#F00"></span></span><span style="position:relative; display: inline; top:3px">Highlight Color</span>');
    }

    buttonsStyling(): void {
        for (let i = 0; i < document.getElementsByTagName('jqxtooltip').length; i++) {
            (<HTMLElement>document.getElementsByTagName('jqxtooltip')[i].firstElementChild).style.display = 'inline-block';
        }

        for (let i = 0; i < document.getElementsByTagName('jqxbutton').length; i++) {
            (<HTMLElement>document.getElementsByTagName('jqxbutton')[i].firstElementChild).style.display = 'inline-block';
            (<HTMLElement>document.getElementsByTagName('jqxbutton')[i].firstElementChild).setAttribute('checked', 'false');
        }

        for (let i = 0; i < document.getElementsByTagName('jqxdropdownlist').length; i++) {
            (<HTMLElement>document.getElementsByTagName('jqxdropdownlist')[i].firstElementChild).style.display = 'inline-block';
        }

        this.fileItemButton.elementRef.nativeElement.firstElementChild.style.color = 'white';
        this.fileItemButton.elementRef.nativeElement.firstElementChild.style.background = 'transparent';
    };

    onBucketColorPicker(event: any): void {
        (<HTMLElement>document.getElementById('bucketColorPreview')).style.background = '#' + event.args.color.hex;
    };

    onSubScriptClick(): void {
        this.superScriptToggleButton.toggled(false);
    };

    onSuperScriptClick(): void {
        this.subscriptToggleButton.toggled(false);
    };

    onFontColorPicker(event: any): void {
        (<HTMLElement>document.getElementById('fontColorPreview')).style.background = '#' + event.args.color.hex;
    };

    onHighlightColorPicker(event: any): void {
        (<HTMLElement>document.getElementById('highlightColorPreview')).style.background = '#' + event.args.color.hex;
    };

    onPasteButtonClick(event: any): void {
        let text = this.pasteButton.elementRef.nativeElement.getElementsByClassName('pasteText')[0].innerHTML;
        console.log(text + ' clicked');
    };

    onMouseDownPasteButton(event: any): void {
        event.preventDefault();
    };

    onPasteDropDownSelect(event: any): void {
        let pasteData =
            [
                { label: 'Paste', imageClass: 'icon page_paste' },
                { label: 'Paste Special', imageClass: 'icon paste_plain' },
                { label: 'Paste text', imageClass: 'icon paste_word' },
                { label: 'Paste link', imageClass: 'icon PasteImage' }
            ];
        let index = event.args.index;
        let icon = '<span class="' + pasteData[index].imageClass + '" style="zoom: 1.5"></span>';
        this.pasteButton.elementRef.nativeElement.firstElementChild.innerHTML = (icon + '<span class="pasteText">' + pasteData[index].label + '</span>');
        this.pasteButton.render();
    };

    fontListSource: string[] =
        [
            "<span style='font-family: Courier New;'>Courier New</span>",
            "<span style='font-family: Times New Roman;'>Times New Roman</span>",
            "<span style='font-family: Arial;'>Arial</span>"
        ];

    fontSizeListSource: number[] = [8, 9, 10, 11, 12, 14, 18, 20, 22, 24];
    fontSizeListRenderer: any = (index, label, value) => {
        return '<span style="font-size:' + value + 'px;">' + value + '</span>';
    };

    changeCaseListSource: string[] = ['Sentence Case', 'lowercase', 'UPPERCASE', 'Capitalize Each Word'];
    changeCaseListSelectionRenderer: any = (object, index, label) => {
        return '<div class="icon change-case-16" style="top:3px;  position:relative"></div>';
    };

    pasteData: any[] =
        [
            { label: 'Paste', imageClass: 'icon page_paste' },
            { label: 'Paste Special', imageClass: 'icon paste_plain' },
            { label: 'Paste text', imageClass: 'icon paste_word' },
            { label: 'Paste link', imageClass: 'icon PasteImage' }
        ];

    pasteRenderer: any = (index: number, label, value) => {
        let labelEl = '<span style="font-size: 10px">' + label + '</span>';
        let icon = '<span class="' + this.pasteData[index].imageClass + '" style=""></span>';
        return '<span>' + icon + labelEl + '</span>';
    };

    pasteRelectionRenderer: any = (object, index, label) => {
        return "";
    };

    gridData: any = this.manageGridData();

    manageGridData(): any {
        let numberrenderer = (row, column, value): string => {
            return '<div style="text-align: center; margin-top: 5px;">' + (1 + value) + '</div>';
        };
        let datafields = [];
        let columns = [];
        for (let i = 0; i < 26; i++) {
            let text = String.fromCharCode(65 + i);
            if (i == 0) {
                let cssclass = 'jqx-widget-header';
                columns[columns.length] =
                {
                    pinned: true,
                    exportable: false,
                    text: "",
                    columntype: 'number',
                    cellclassname: cssclass,
                    cellsrenderer: numberrenderer
                };
            }
            datafields[datafields.length] = { name: text };
            columns[columns.length] = { text: text, datafield: text, width: 60, align: 'center' };
        };
        let source =
        {
            unboundmode: true,
            totalrecords: 100,
            datafields: datafields,
        };
        let dataAdapter = new jqx.dataAdapter(source);
        let jqxRibbonSettings: jqwidgets.GridOptions =
        {
            source: dataAdapter,
            columns: columns
        };

        return jqxRibbonSettings;
    };
}

Summary

jQWidgets UI for Angular provides an easy way to integrate robust UI components into your Angular project. By using either the ng add command or manual setup, you can quickly get started. Once the setup is complete, you can add the desired jQWidgets components and configure them in your Angular components to match your application requirements.

Ribbon API

API Reference of the jQWidgets Ribbon component for Angular: Ribbon API