Selecting the Appropriate Table Columns to Display

I currently have a table that includes columns for first name, last name, place of birth, date of birth, and three additional fields. Positioned above the table is a button that triggers a modal window containing checkboxes representing each column.

Below is the code snippet for these checkboxes:

    <div *ngFor="let column of columns">
         <md-checkbox id="{{column.name}}"
                      [checked]="checked"
                      [(ngModel)]="setColumn"
                      (click)="showColumn($event, column.name)">{{ column.name }}</md-checkbox>
   </div>

The goal is to only display the columns for first name and last name when their respective checkboxes are selected before clicking the save button.

Can anyone provide guidance on accomplishing this task?

EDIT: The following is the code responsible for rendering the table:

<div class="table">
    <div class="row">
        <div class="col">
            <label>
                <a (click)="sortColumn('firstName')">
                    First Name<span>
                        <i *ngIf="order==1" class="fa fa-caret-down"></i>
                        <i *ngIf="order==(-1)" class="fa fa-caret-up"></i>
                    </span>
                </a>
            </label>
        </div>
        <div class="col">
            <label>
                <a (click)="sortColumn('lastName')">
                    Last Name<span>
                        <i *ngIf="order==1" class="fa fa-caret-down"></i>
                        <i *ngIf="order==(-1)" class="fa fa-caret-up"></i>
                    </span>
                </a>
            </label>
        </div>
        <div class="col">
            <label>
                <a (click)="sortColumn('placeOfBirth')">
                    Place of Birth<span>
                        <i *ngIf="order==1" class="fa fa-caret-down"></i>
                        <i *ngIf="order==(-1)" class="fa fa-caret-up"></i>
                    </span>
                </a>
            </label>
        </div>
        <div class="col">
            <label>
                <a (click)="sortColumn('birthdate')">
                    BirthDate<span>
                        <i *ngIf="order==1" class="fa fa-caret-down"></i>
                        <i *ngIf="order==(-1)" class="fa fa-caret-up"></i>
                    </span>
                </a>
            </label>
        </div>
    </div>
    <div class="row" *ngFor="let user of users | sortingTable:path:order | paginate: { itemsPerPage: 45, currentPage: p}">
        <div class="col">
            <label>{{ user.firstName }}</label>
        </div>
        <div class="col">
            <label>{{ user.lastName }}</label>
        </div>
        <div class="col">
            <label>{{ user.placeOfBirth }}</label>
        </div>
        <div class="col">
            <label>{{ user.birthdate }}</label>
        </div>
    </div>
</div>

Answer №1

Assuming we have two components: ModelComponent.ts and Checkbox.component.ts

In the modal, create a 'change' function on the checkbox. When you check or uncheck it, this event will be triggered. Store all the values of checked checkboxes in an array. For example, if you check 'firstName' and 'lastName', your array should contain these two values. When you click save and pass this array as a parameter, you can use a shared Service to communicate between the two components. Utilize BehaviourSubject and subscribe to it in the checkbox.component.ts file. Refer to this link for bidirectional communication between components using a service.

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

Best Practices for Integrating Angular with Your Custom JavaScript Library

Imagine needing to create a TypeScript function that can be utilized across various components, services, or modules. For example, let's say you want an alert wrapper like this: my_alert(msg); // function my_alert(msg) { alert(msg); } You might hav ...

What is the best way to invoke a method within the onSubmit function in Vuejs?

I am facing an issue with a button used to log in the user via onSubmit function when a form is filled out. I also need to call another method that will retrieve additional data about the user, such as privileges. However, I have been unsuccessful in makin ...

Encountering an unexpected termination error when using Typescript, pg, Express, and Psql within a Docker container: "Error: Connection terminated unexpectedly"

I am facing an issue with connecting to my database running on a Docker container using a postgres image: docker run --name postgres-container -p 2345:2345 -e POSTGRES_PASSWORD=password123 -e POSTGRES_USER=admin -d postgres The TypeScript code I have is i ...

Personalize the bootstrap classes within Angular app development

I'm currently utilizing bootstrap 4 and sass within my angular 6 application development. My goal is to create a customized nav tab in my application by slightly modifying the bootstrap nav-tabs and nav-link classes. However, the changes I make to th ...

IE11 displaying empty placeholders instead of PrimeNG icons after deployment on server

Currently, I am in the midst of an Angular project that heavily relies on PrimeNg for various components. While everything runs smoothly when testing the project locally across all browsers (including IE11 and Chrome), a hiccup arises once the project is ...

Utilize RobotFramework to conduct a Google search for a specific item

I'm having trouble figuring out how to configure my robot framework script to perform a basic Google search. Here is my code: *** Settings *** Documentation This test is very simple Library ...

The error message "global.HermesInternal - Property 'HermesInternal' is not found in the type 'Global & typeof globalThis'" appeared

I ran the auto-generated code below: $ react-native init RepeatAloud App.tsx /** * Sample React Native App * https://github.com/facebook/react-native * * @format * @flow strict-local * ...

Retrieving ACCESS_TOKEN from Instagram redirect using Angular 5 (Implicit Authentication)

Building a frontend app without a backend, I have decided to use Instagram implicit authentication. However, once the user authorizes the app, Instagram redirects to my redirect_uri with the access token in this format: http://your-redirect-uri#access_to ...

Scrolling to the bottom of an ion-content in Ionic 4

I am currently developing a chat page with Ionic 4 and I'm attempting to implement an automatic scroll feature to the bottom of the page. However, the method I tried using doesn't seem to be working as expected: import { IonContent } from "@ioni ...

Error 404 occurs when attempting to retrieve a JSON file using Angular's HTTP

I'm having an issue with my service code. Here is the code snippet: import {Injectable} from '@angular/core'; import {Http, Headers, RequestOptions} from '@angular/http'; import 'rxjs/add/operator/map'; import {Client} f ...

Angular 2 GET request returns a 404 error

I have been attempting to reproduce the ngPrime datatable demo from this Github repository. Currently, I am working with the most recent version of Angular (4) and using angular-cli in development mode. Placing a JSON file into my app folder where the serv ...

Launching superheroes application developed with Angular 2

I followed the heroes tutorial and customized my own Angular2 application using some components. Although it resembles the heroes tutorial, I have successfully set up everything with my IDE and npm. Now, I am facing challenges in deploying my application i ...

What steps are needed to successfully integrate Angular 2 final (2.0.0, post rc7) and TestBed in this Plunkr project?

My goal is to start using the TestBed functions, but I am having trouble initializing it. In my src/test.spec.ts file, I tried the following code without success: TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); ...

How can you transfer array elements to a new array using JavaScript?

I have a task to transform the fields of an array received from one server so that they can be understood by another server for upload. My approach involves first retrieving and displaying the original field names from the initial server's array to al ...

I built a custom Angular application integrated with Firebase, and I'm looking for a way to allow every user to have their individual table for managing tasks

I am looking to enhance my code so that each user who is logged in has their own tasks table, which they can update and delete. Additionally, I need guidance on how to hide menu items tasks, add-tasks, logout for users who are not logged in, and display th ...

Utilizing TypeScript code to access updatedAt timestamps in Mongoose

When querying the database, I receive the document type as a return. const table: TableDocument = await this.tableSchema.create({ ...createTableDto }) console.log(table) The structure of the table object is as follows: { createdBy: '12', cap ...

Encountering difficulties in starting a new Angular project using a Mac operating system

Attempting to set up a fresh Angular project named 'test' on a Mac. The command used in Terminal is as follows: xxxx$ ng new test Upon execution, the following error is displayed: -bash: /Users/xxxx/.npm-packages/lib/node_modules/@angular/cli ...

Resolving the issue of missing properties from type in a generic object - A step-by-step guide

Imagine a scenario where there is a library that exposes a `run` function as shown below: runner.ts export type Parameters = { [key: string]: string }; type runner = (args: Parameters) => void; export default function run(fn: runner, params: Parameter ...

Having trouble installing Popper.js?

I have encountered an issue while attempting to install popper.js in my angular project. ng new <<project>> cd <<project>> npm install popper --save npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules&b ...

Deleting an element from an object in TypeScript

Is there a way in TypeScript to exclude certain elements (e.g. 'id') from an object that contains them? ...