Identifying row expansion in ngx-datatable: detecting expand status on row click

Is there a way to determine if a line has already been expanded when using the toggle feature? When you click on a line, it expands and shows the details. Here is some code in HTML:

 <ngx-datatable
   #dataTable
   ...
   (select)='onRowSelect($event)'
   (activate)="onLoadDataDetails($event)">

In TypeScript:

  onRowSelect(row: any): void {
    if (row && row.selected) {
      this.dataTable.rowDetail.toggleExpandRow(row.selected[0]);
    }
  }

  onLoadDataDetails(row: any): void {
    if (row.type === 'click') {
      this.loadDetails(row.row.id);
    }
  }

If the request (this.loadDetails) is triggered every time a line is opened or closed, how can we prevent that?

Answer №1

I was able to successfully resolve this issue by adding a method to set an internal variable.

<ngx-datatable-row-detail
 #myDetailRow>
  <ng-template let-row="row" let-expanded="expanded" ngx-datatable-row-detail-template>
    <div *ngIf="expanded?setExpandStatus(expanded):false"></div>

Here is the code snippet for the component:

  setExpandStatus(expanded: any): void {
    this.rowIsNotExpanded = expanded;
  }

  onLoadDataDetails(row: any): void {
    if (row.type === 'click') {
      if (!this.rowIsNotExpanded) {
        this.loadDetails(row.row.id);
      }
    }
  }

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

Removing an attachment from the attachment object array nestled within a comment object array nested inside another object array

I am currently grappling with the challenge of removing an attachment from an array of attachments within a nested structure of comment objects. Despite several attempts, I have yet to find a solution that works effectively. export class CommentSection{ ...

Tips on Importing a Javascript Module from an external javascript file into an <script> tag within an HTML file

I'm facing an issue while attempting to import the 'JSZip' module from an external node package called JSZip in my HTML File. The usual method of importing it directly using the import command is not working: <script> import ...

Bringing in TypeScript definitions for gridster

After starting a new ionic project, I decided to include the gridster.js library by running npm install gridster and npm install @types/jquery.gridster in the root directory of my project. However, when trying to import the installed definitions, I encount ...

What is the best data type in Asp Net Core C# for capturing Angular's blob object?

I am working with an image BLOB object in Angular 5 and need to send it to the backend via an API. In previous versions of Asp.Net, there was 'HttpBaseType' for this purpose, but it is not available in Asp.Net core. Which data type should be use ...

Using Typescript to create an asynchronous function without explicitly declaring a Promise

When you examine TypeScript's async function, you may notice the redundancy with "async" and "Promise<type>". public async test(): Promise<string> { return "Test"; } Is there a way to configure TypeScript to handle async types ...

Angular2 with Webpack causes duplication of styles in the header

I'm currently working on integrating Angular2 with universal + webpack, but I have encountered an issue where styles are being loaded twice in the head element. I haven't made any changes to the git repo that I forked from. You can find it here: ...

Tips for incorporating multiple services within a single Angular component

Issue found in src/app/header1/header1.component.ts:3:30 - TypeScript error TS2306: The file 'F:/Angular-projects/lawyer-listing/src/app/services/state.service.ts' is not recognized as a module. 3 import { StateService } from '../services/st ...

Issue: Inadequate parameters have been supplied for the localized pathname (getPathname()). This problem arose after the inclusion of "next-intl/routing" module

After implementing the config file and replacing : Navigation File import { createLocalizedPathnamesNavigation, Pathnames } from 'next-intl/navigation'; With : Config File import {Pathnames, LocalePrefix} from 'next-intl/routing';} ...

Repositioning the initial location of mat-slider

Currently, I am working on the mat-slider component and I have a specific requirement. I need to position the thumb in the middle and allow it to slide both left and right. Here is my code: https://stackblitz.com/edit/angular-9unenq-utcytk?file=app%2Fslid ...

Angular 5 - Empty array containing objects has a length of zero

In my app.component.ts file, I have an array initialized to load objects in the onInit event: ngOnInit() { this.pages = []; } Within the ngOnInit event, I also have a setInterval method that evaluates an expression every few milliseconds: setInterval(() ...

Having trouble resolving parameters? Facing an Angular dependency injection problem while exporting shared services?

Seeking to streamline the process of importing services into Angular 4 components, I devised a solution like this: import * as UtilityService from '../../services/utility.service'; As opposed to individually importing each service like so: imp ...

Displaying HTML content using Typescript

As a newcomer to typescript, I have a question regarding displaying HTML using typescript. Below is the HTML code snippet: <div itemprop="copy-paste-block"> <ul> <li><span style="font-size:11pt;"><span style="font-family ...

Angular 2's Http Post function mistakenly triggers dual ajax requests instead of a single one

Greetings! I have been delving into the implementation of the observable pattern in Angular and seem to be facing some issues. Below is the code snippet that is causing trouble: import 'rxjs/Rx'; import {Injectable, EventEmitter} from 'ang ...

Every time I attempt to create a new ionic project using angular through the console, I encounter the error message: "npm ERR! Cannot read properties of undefined (reading 'isServer')"

Having an issue with npm where it is giving the error "Cannot read properties of undefined (reading 'isServer')." I have updated npm to the latest version and tried force-clearing the cache, but the issue persists. Can anyone provide assistance? ...

The first click does not trigger the update for the md-autocomplete

After successfully implementing md-autocomplete in my Angular4 app, I encountered a problem where the options do not show up when the list is first clicked, unlike in the demo. The options only appear once a selection is made. Here is the HTML code: &l ...

Typescript sometimes struggles to definitively determine whether a property is null or not

interface A { id?: string } interface B { id: string } function test(a: A, b: A) { if (!a.id && !b.id) { return } let c: B = { id: a.id || b.id } } Check out the code on playground An error arises stating that 'objectI ...

swap out an element in an array with an extra element

My array contains elements with both id and des properties. I would like to add an additional property like value:0 to each object in the array. I achieved this using a loop. let data = [ { "id": 1001, "des": "aaa" }, { ...

How to make a routerLink clickable within an anchor tag in Angular 6

I am facing a peculiar issue with a group of hyperlinks. html <div class="col-12 navlinks"> <div class="text-center"> <div class="justify-content-center"> <a class="col-auto d-inline-block whitelink" rou ...

Aliases in Typescript are failing to work properly when used alongside VSCode Eslint within a monorepository

I've incorporated Typescript, Lerna, and monorepos into my current project setup. Here's the structure I'm working with: tsconfig.json packages/ project/ tsconfig.json ... ... The main tsconfig.json in the root directory looks lik ...

CORS policy has blocked the Node.JS OvernightJS Express CORS XMLHttpRequest request

I have a back-end API created using Node.js and Typescript that is listening on localhost:3001. Additionally, I have a front-end application built with Angular and Typescript that is listening on localhost:4200. Currently, I am attempting to upload an ima ...