Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
365
Angular igx-grid - Tool tip(Pop up) with button
posted

Hi ,

We are using Angular igx-grid. if the column length exceeds certain limit by default Grid adds ... towards the end and shows the full text as part of tool tip.

can we customize this feature like keeping an icon instead of ... and clicking on the icon opens kinda of dialog or overlay so user have the flexibility to read the full text t

Parents
  • 460
    Offline posted

    Hello,

    I have been looking into your question and to customize the igx-grid column headers and display an icon instead of the default ellipsis (...), you can implement the following steps. This will allow users to click the icon to open a dialog displaying the full text of the column header.

    Steps to Customize igx-grid Column Headers

    1. Define the Grid with a Custom Header Template:
      • Use the igxHeader template to customize the header of a specific column.
      • Display the first part of the header text and an icon that will open a dialog when clicked.
    2. Implement the Dialog for Full Text Display:
      • Use the IgxDialogComponent from Ignite UI to create a dialog that shows the full header text when the icon is clicked.

    <ng-template igxHeader let-column>
            <div class="header-content">
              <!-- Display first two words and an icon for longer headers -->
              <span *ngIf="column.header.length > maxLength">
                {{ getFirstTwoWords(column.header) }}
                <igx-icon family="material" (click)="openDialog(column.header)">more</igx-icon>
              </span>
              <!-- Display full header if it's short enough -->
              <span *ngIf="column.header.length <= maxLength">{{ column.header }}</span>
            </div>
    </ng-template>

     

    <!-- Dialog to show full header text -->
    <igx-dialog #dialog>
      <igx-dialog-title>Full Header Text</igx-dialog-title>
      <div>{{ fullText }}</div>
      <igx-dialog-actions>
        <button igxButton="contained" (click)="closeDialog()">Close</button>
      </igx-dialog-actions>
    </igx-dialog>

     

    @ViewChild('dialog', { static: true }) public dialog: IgxDialogComponent;
    
      public data: any[];
      public maxLength = 10; // Maximum length for header text before truncation
      public fullText = '';
    
      constructor() {}
    
      ngOnInit() {
        // Initialize data
        this.data = DATA;
      }
    
      // Method to get the first two words of a string
      public getFirstTwoWords(text: string): string {
        return text.split(' ').slice(0, 2).join(' ');
      }
    
      // Method to open the dialog with the full header text
      public openDialog(text: string) {
        this.fullText = text;
        this.dialog.open();
      }
    
      // Method to close the dialog
      public closeDialog() {
        this.dialog.close();
      }

    Key Points

    1. Custom Header Template:
      • Uses ng-template igxHeader to define a custom template for the column header.
      • Checks if the header length exceeds maxLength. If it does, it displays the first two words and an icon.
      • If the header is within the maxLength, it displays the full header text.
    2. Icon and Dialog:
      • The icon is an igx-icon with a click event bound to the openDialog method.
      • openDialog sets the full header text to a variable (fullText) and opens the dialog.
      • The dialog shows the full header text and includes a close button that triggers closeDialog to close the dialog.

    The described scenario could be observed here:

     

    In addition, I have prepared small sample illustrating this behavior which could be found here. Please test it on your side and let me know how it behaves.

    If you require any further assistance on the matter, please let me know.

    Regards,

    Georgi Anastasov

    Entry Level Software Developer

    Infragistics

Reply Children