Finding the right spot to apply CSS styles in a data table can be a tricky task

I need to use angular-ngStyle to apply CSS styles on Table data.

The logic is set up: "When the table width is less than 1250px, apply certain CSS styles". Here is the code for that:

export class NanoTableComponent {

/**
 * This function checks the table width and applies styles if the width is less than 1250px;
 * The challenge is figuring out where to place this logic in the HTML.
 */
tableStyle(tableWidth: number) {
    console.log('Table Width: ' + tableWidth);
    return tableWidth < 1250 ? { 'min-width':'75px;', 'flex':'none;' } : { 'flex': '1' };
}
}

In the SCSS class

// ********* THE ISSUE IS HERE **********
// If I change flex: none; and min-width: 75px; in this div 
// I can achieve what I want. But I only want this if the table width is less than 1250px;
// Meaning these styles need to be added dynamically through Angular,
// the problem lies in where to apply these styles in the HTML.
> div {
  flex: 1;
  display: flex; 
  overflow: hidden;
  margin: 0 2px;
  > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

Here is a StackBlitz with HTML, TypeScript, and SCSS files. It's not functional, but you can view all the code related to this table:

https://stackblitz.com/edit/angular-css24?file=src%2Fapp%2Fnano-table%2F_nano-table.scss

My question is: How can I access and apply the styles of the "div" from the SCSS file dynamically in the HTML?

My objective is to increase the width of the "Name" column to make it larger:

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

Answer №1

Give your table a unique style based on its width

<div class="nano-table-row nano-table-grid-header" #table [class.custom-style]="table.offsetWidth< 1250" >

Then apply specific CSS rules to that custom class

 .custom-style
{
 //specific styling goes here
}

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

I possess information stored within the array object below, and I aim to transform it into a different array object format

Here is the response I received from my API: let data = [ { date: '2021-04-27', formatted_date: 'Apr 27', location: [ { date: '2021-04-27', formatted_date: 'Apr 27', countr ...

Create a custom data type that consists of a specific set of keys from an object

Is there a way to create a type in TypeScript that includes only a subset of keys from an object? Consider the example object below: const something = { cannary: "yellow", coyote: "brown", fox: "red", roses: "white", tulipan: "purple", palmera: ...

When using ngModel, the Tinymce Angular 2+ templates do not initially replace values, whereas they do when templates are inserted by the user

In my Angular 7 app, I am utilizing the TinyMCE editor component. When I insert a template variable into the editor: <span class="data-variable">${variable_name}</span> The variable gets replaced successfully with a value from the `template_r ...

The button in the flex container is not wide enough due to center alignment

For my project, I implemented a CSS grid layout consisting of 20 rows and 20 columns (5% of screen for each cell). One particular page includes a button that initially fit within grid columns 5-8 and rows 6-9 without any issues. However, I wanted to center ...

Transferring an Angular 2 component with output parameters to Angular 1 via Downgrade

After successfully downgrading an Angular 7 component to Angular 1, I encountered a small issue that has proven difficult to resolve. The output parameter in my downgraded component is defined as: @Output()isValid = new EventEmitter<boolean>(); An ...

Having trouble getting PostCSS nesting to work with CSS variables in Tailwind CSS and Next.js?

I've been attempting to utilize PostCSS nesting alongside CSS variables, but unfortunately the CSS variables are not being converted at all. Instead, I am seeing Invalid property value in the DOM for CSS Variables. The tailwind.css file I have inclu ...

Is there a way to adjust the width of my web layout without sacrificing its responsiveness?

Struggling with my website layout design as I encountered an issue. The overall width of the layout is too excessive, and I want to introduce some margins on the sides for a better visual appeal. Although the responsive design works well originally, adding ...

CSS Hyperref and Anchor tags

It appears that when adding an 'href' tag to my anchor, all of the CSS formatting is lost. Is there a special way that CSS treats links? Below is the basic CSS: .topmenu > ul > li > a:visited, .topmenu > ul > li > a:active, .t ...

Utilizing Angular's ngIf directive to output the result of a condition

In my project, there is a unique card-list element that has the capability to display either elements from the card component or the card-edit component based on the value of the wasEditClicked property in the card component. The structure of the card-lis ...

Connect reactive form to material date picker control

I implemented a date picker that should be dynamically disabled or enabled based on a checkbox toggle click. I am using all components from the Angular Material 6 library, and because I am following a reactive approach for handling my forms, I cannot simpl ...

Only IE7 seems to be experiencing a z-index problem with CSS that is not present on any

I’ve encountered a perplexing problem with CSS z-index in IE7 that I just can’t seem to solve. #screen { display: none; background-image: url('/images/bg.png'); background-repeat: repeat; position: fixed; top: 0px; le ...

Issue with using variables in nodejs, express, and EJS: Undefined

Having some trouble with EJS here. I am using response.render('agent.html', {name: 'aaaa'});, and in my HTML script, I attempt to access <%= this.name %>. Unfortunately, I keep getting a ReferenceError: aaaa is not defined. Any su ...

Html5 canvas not resizing to fit container

I'm currently working on creating a square canvas using CSS to ensure it is instantly sized when the page loads. To achieve this, I am wrapping the canvas in a div and applying the following styles: http://jsfiddle.net/evopgwzd/ body { backgrou ...

Triggering transitionend event once with an added if condition

Currently, I have an application of an if statement that examines whether an element contains a style attribute. In the event that the style attribute is absent, it appends inline styling. Conversely, if the style attribute exists, it is removed. Furthermo ...

fill out an HTML form and send it in

When submitting a form with two components, only the first form 'School' and the submit button itself are successfully submitted. The second form 'pool' seems to disappear somehow. <form method='get'> <select nam ...

Troubles arise when trying to encapsulate a ReactJS embedded application with Material ui, causing issues with the

Currently, I am integrating a ReactJS application using Material UI styled components within a Wordpress page. To achieve this, I am utilizing webpack for transpilation of the JavaScript. After generating the bundle for the embedded version of the applica ...

Choose from an array of over 50,000 row options

I am currently facing an issue with my database which contains approximately 50,000 records, all related to business partners. Currently, I am using the following code: <select name="selection"> -- some while loop <option></option> (thi ...

JavaScript to toggle the visibility of elements when they move outside of a specified container

Check out this js+html/css project I worked on: http://jsfiddle.net/A1ex5andr/xpRrf/ It functions as intended - opening and closing with the use of .advSearch-btn to open/close, and .advSearch-control .canc to close. However, I am facing an issue where it ...

Utilize Firebase to perform a case-insensitive query

Our Angular/Ionic app requires users to provide their email during registration, which is then saved in the User collection. We also validate if the email is already in use with a query like this: firestore .collection("User") .where("email", "==", ...

Tips for displaying the message "{"POWER":"ON"}" within the else if statement (this.responseText == ({"POWER":"ON"})) {

Hey everyone, I'm trying to adjust the color of a button on my webpage based on the response I receive from this.responseText. I understand the JSON response, but for some reason, I can't seem to incorporate it into my code. If anyone could lend ...