In ngx-datatable, I’ve set up a unique custom dropdown component within every header cell

I have a custom dropdown component in each header cell of my ngx-datatable. However, when I click on the dropdown, it is going inside the body of ngx-datatable. Can someone please help me resolve this issue?

My development environment includes Angular 4.0 and TypeScript 2.4.

Attached screenshots: https://i.sstatic.net/jIWVR.png

https://i.sstatic.net/RwQtB.png

Below is my code snippet:

 <div>
      <ngx-datatable style="height:450px;"
        class='material'
        [rows]='activeTabData | filtermanual:propKey:propValue | orderBy : {property: column, direction: direction}'
        [columnMode]="'force'"
        [headerHeight]="height"
        [rowHeight]="getRowHeight"
        [scrollbarV]="true"
        [scrollbarH]="true"
        [loadingIndicator]="loadingIndicator"
        [rowClass]="getRowClass"
        (page)="onPage($event)">
      <div>
        <ngx-datatable-column 
          [width]="50"
          [frozenLeft]="true">
            <ng-template let-row="row" let-value="value" ngx-datatable-cell-template >
              <input type="checkbox" 
              (ngModelChange)="checkButtonState($event, row)"
              [ngModel]="row.status"
              >
          </ng-template>
        </ngx-datatable-column>

        <ul>
          <li *ngFor="let col of tableKeys; let i=index; let last = last" >
        <ngx-datatable-column name={{col}} width="230" [resizeable]="true">
          <ng-template let-column="column" ngx-datatable-header-template >
              <div class="draggable" style="height:30px;width:160px;background:transparent;z-index:1000;position:relative;cursor:pointer;"></div>

                                    <ng2-multiselect 
                                      [options]="dropdowns[col]"
                                      [loading]="isLoading"
                                      [(ngModel)]="multiModels[col]"
                                      [texts]="{'defaultTitle':col}"
                                      (dropdownOpen)="dropdownOpen()"
                                      (dropdownClosed)="dropdownClosed(col)"
                                      >
                                    </ng2-multiselect>   
        </ng-template>

          <ng-template let-row="row" let-value="value" ngx-datatable-cell-template >
              <i [innerHTML]="row[col]"></i>
          </ng-template>
        </ngx-datatable-column>

          </li>
        </ul>
      </div>
      </ngx-datatable>
    </div>

Answer №1

When dealing with the ngbDropdown dropdown, I was able to fix a similar problem by including the container="body" attribute like so:

<div ngbDropdown class="d-inline-block" container="body">
....
.....
</div>

Answer №2

To enhance your component styling, consider incorporating the code snippet below:

.custom-datatable {
  overflow: auto;
  .datatable-header {
    overflow: hidden;
    .datatable-header-cell {
      overflow-x: scroll;
    }
  }
}

Answer №3

Encountered a similar issue:
My personalized dropdown got hidden behind the <datatable-body>.
Resolved it by following these steps:

.datatable-header-cell,
.datatable-header {
    overflow:visible !important;   
}
.datatable-row-center {
   z-index:11;
}

However, when using horizontal scrolling with [scrollbarH], the content within the <datatable-header> spilled over horizontally. To address this, I placed my <ngx-datatable> inside a <div> and applied overflow:hidden to it.

Hoping that this solution proves helpful for someone else down the line. :)

Answer №4

For anyone looking for a solution, I came across this helpful method: 1) Utilize @ng-select/ng-select 2) Simply add the attribute: appendTo="body", like so:


<ng-select [items]="simpleItems"
               appendTo="body"
               [(ngModel)]="selectedSimpleItem">
    </ng-select>

No need to worry about any additional z-index configurations.

Answer №5

Sharing templates can easily be achieved by incorporating a TemplateRef as a ViewChild.

For instance, consider the following scenario:

Assume we have specific columns along with a template (situated outside the columns):

   <ngx-datatable-column prop="deadline" name="Deadline" [cellTemplate]="dateTemplate">
   <ngx-datatable-column prop="entryDate" name="Entry date" [cellTemplate]="dateTemplate">

   <ng-template #dateTemplate let-value="value">{{value | date:"shortDate"}}</ng-template>

In this example, I am binding [cellTemplate] to the dateTemplate. The date template is declared in my component as a ViewChild using a template reference.

export class TableComponent implements OnInit {
  @ViewChild("dateTemplate") dateTemplate: TemplateRef<any>;

...

In your situation, you can follow a similar approach but utilize [cellHeaderTemplate] instead of [cellTemplate]!

Answer №6

simply using ViewEncapsulation.None in the component along with

datatable-body-cell {
  overflow: visible !important;
}

in the .css or .scss file solved the issue for me.

Answer №7

I encountered a comparable problem when trying to display a drop-down (utilizing ngbTypeahead) within ngx-datatable columns. The solution that worked for me was adding container="body" to the input element.

<input name="abc" [ngbTypeahead]="searchElement" container="body"/>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The routing on the Angular app is malfunctioning after deployment via Azure Static App

After using ng build --prod to create the dist folder locally, I proceeded to set up a storage account in Azure and enabled "Static App." I then uploaded the contents of the dist/xxx folder to the $web folder. However, when trying to navigate to any route, ...

What is the best way to apply a custom date format of 'MM/DD/YYYY H:MM am/pm' with moment.js?

I recently started using Angular4 and moment.js to work with dates. I created a custom format: 'MM/DD/YYYY H:MM am/pm' but I'm having trouble implementing it correctly. Here is my Component.ts file: import * as moment from 'moment&apo ...

Angular: Safely preserving lengthy content without the use of a database

As a beginner working on an Angular 11 educational website with approximately 20 static articles, I created a component template for the articles to receive text inputs. However, I am wondering if there is a more efficient way to handle this. Is there a ...

What could be causing the interface to malfunction when defining a type that includes an enum as a property key?

When dealing with an enum and wanting to use its values as keys in objects, the type declaration looks like this: enum Bar { A, B } let dictionary: BarDictType = { [Bar.A]: "foo", [Bar.B]: "bar" } type BarDictType = { ...

How can you set a checkbox to be selected when a page loads using Angular?

On page load, I need a checkbox to already be 'checked', with the option for the user to uncheck it if they want. Despite trying to add [checked]="true" as recommended in some Stack Overflow answers, this solution is not working for me. <label ...

Issue with *ngIf on Nativescript not functioning properly on iOS

I am encountering a major issue in my project. The *ngIf directive I am using is functioning only on the Android platform and not on iOS. Here is the HTML code snippet: <GridLayout columns ="auto, auto" rows="*" (tap)="open()"> <StackLayout co ...

Is it possible to efficiently structure intricate JSON data onto interfaces in TypeScript with the incorporation of observables?

I am currently working on creating a simple web news reader that relies heavily on the Google News API (). I have set up all the necessary services, models, etc. However, I am having difficulty mapping the data onto specific interfaces. The Google API retu ...

Is there a way to reset the yAxes count of a chart.js chart in Angular when changing tabs?

I am currently using chart.js within an Angular framework to visually display data. Is there any method available to reset the y-axis data when changing tabs? Take a look at this Stackblitz demo for reference. Upon initial loading of the page, the data ...

What's the best way to implement satisfies with a generic type?

In my development process, I am working with components that have default values combined with props. To streamline this process, I created a single function for all components: export function getAssignProps <T extends {}>(propsMass:T[]){ return ...

What is the syntax for typing a mongoose populated field in Typescript?

I am faced with a field that can either be an ID or have a value, and I am attempting to type this field using TypeScript import { InferSchemaType, Schema, Types, model } from 'mongoose'; const personSchema = new Schema({ _id: Schema.Types.Obj ...

Upgrading from Angular 5 to 6: Embracing the RxJS Changes without the crutch of rxjs

Currently, I am facing the challenging task of migrating a project from Angular 5.2.11 to version 6.0.0. The main issue I'm encountering is with RxJS 6 (which is essential for Angular versions above 6). Here's an example of one of the errors that ...

The disappearing act of embedded Twitter timelines in Ionic 2

My code displays the timeline initially, but it disappears when I navigate away from the view. Can anyone help me troubleshoot this issue? Upon first visit to the view, the timeline is visible, but upon returning, it disappears. Below is the code snippet ...

Querying the Firebase real-time database and refining the output using an Angular pipe

I developed a web application that sends a request to the Firebase realtime database to retrieve user information. When the service calls the following method, the information is returned: //searches db for user information getUserInfo(uid){ return t ...

I am looking to include both a space and a comma in the State dropdown value in an Angular application

I am facing an issue with my dropdown in Angular 9. When the State is more than one, it displays without any space between them. I want it to show like: Licensed State:ARCA I need like: AR, CA This is the code I have so far: <ng-c ...

Utilizing ngrx/store in Angular 2 for Search Functionality

In the process of enhancing an angular 4 application, I am working on integrating a search functionality for a data-filled table. The application also utilizes ngrx store to manage state. I am looking for advice on the most effective approach to implemen ...

Can data from an Angular app be accessed by an external JavaScript code within the same project?

I've been thinking about a theoretical scenario that luckily I haven't encountered yet. Imagine I have an Angular Project compiled in My PROJECT FOLDER. <br/> Inside this PROJECT FOLDER, there's another JAVASCRIPT FILE external to ...

Setting up a project with Angular 2 and NodeJS

Hello there, I have some inquiries about organizing the project structure of a MEAN application with Angular2. Initially, I followed the introductory guide on angular.io to create a basic Angular2 app. Now, I am attempting to incorporate this app into a N ...

Ensure that enums in Typescript are initialized explicitly

Is there a way to explicitly initialize the following enum in typescript? enum BloodGroup { OPositive = "O +ve", ONegative = "O -ve", APositive = "A +ve", ANegative = "A -ve", } I attempted something like this (I know it won't wo ...

What exactly does RouteComponentProps entail?

While exploring information on React, I came across the term RouteComponentProps. For example: import { RouteComponentProps } from 'react-router-dom'; const ~~~: React.FC<RouteComponentProps> and class BookingSiteOverview extends React.Com ...

"Securing your Angular application: A guide to encrypting and decrypting

Within my current project, there are two main modules: Staff and Agent. When I click on the Agent module list, the URL displays as "Agent/list" and when updating an Agent, the corresponding ID is passed in the URL. However, I am interested in passing enc ...