Tips for customizing the color scheme of background, rows, row selection, and headers in Angular 4 using Bootstrap 4 data tables

I've integrated Bootstrap 4 data table in my Angular 4 project, but I'm struggling to customize row colors, row selection colors, and header colors.

You can check out the example of the data table I'm using at this link: https://github.com/afermon/angular-4-data-table-bootstrap-4

For a live demonstration, you can visit demo 1 by following this link:

Answer №1

Upon reviewing the code snippet within data-table-component-demo1.ts from the Git project you have downloaded:

<data-table id="persons-grid"
        [header] = "false"
        [multiSelect] = "false"
        [substituteRows]="false"
        [indexColumn]="false"
        [items]="items"
        [itemCount]="itemCount"
        (reload)="reloadItems($event)"
        [pagination]="false"        
        (rowClick)="rowClick($event)"
        [rowColors] = "callBackForChangineRowColors" 
        >
        <data-table-column 
            [property]="'name'"
            [header]="'Name'"            
            [sortable]="true"
            [styleClass]="someExplicitClass" 
  1. You can assign 'someExplicitClass' to [styleClass] as seen above and define this class in the data-table-component-demo1.css file like so:

    :host /deep/ .someExplicitClass{ background-color:red; }

    However, this style applies to the entire DataColumn rather than specific aspects.

  2. To apply only the background color indirectly, utilize the rowEvent variable within the rowClick(rowEvent) function in 'data-table-component-demo1.ts'

    When clicking on a row, set the selected property to true triggering the onRowSelectChanged function in table.component.ts

By setting [rowColors] to "callBackForChangineRowColors" and adjusting data-table-component-demo1.component.ts with the following changes:

rowClick(rowEvent) {
        console.log('Clicked: ' + rowEvent.row.item.name);
        rowEvent.row.selected = true;        
    }

    callBackForChangineRowColors(a,b,c)
    {
        if(b.selected)
        return 'blue';
    }

This approach explicitly assigns blue color to the selected Row.

*Unfortunately, there is no readily available input parameter like [styleClass] to apply other styles specifically at a granular level, as it wasn't exposed as an @Input in column.component.ts. If you have any solutions or ideas, please share them.

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

Material-UI and TypeScript are having trouble finding a compatible overload for this function call

Currently, I'm in the process of converting a JavaScript component that utilizes Material-ui to TypeScript, and I've encountered an issue. Specifically, when rendering a tile-like image where the component prop was overridden along with an additi ...

The @angular/fire package is unable to locate the AngularFireModule and AngularFireDatabaseModule modules

I am facing some challenges while trying to integrate Firebase Realtime Database into my Angular project. Specifically, I am encountering difficulties at the initial step of importing AngularFireModule and AngularFireDatabaseModule. To be more specific, I ...

Complications arising from IE when using strict doctype with CSS and jQuery

Here's the code I'm using for a sliding caption effect on my gallery site: I specifically implemented the last effect which is the Caption Sliding (Partially Hidden to Visible). $('.boxgrid.caption').hover(function(){ $(".cover", th ...

What are the best practices for utilizing pre-defined CSS classes in Vue.js libraries?

I don't have much experience with CSS, but I'm really eager to customize the appearance of my chart. The chart is generated by a vue.js library and comes with pre-defined CSS classes. However, I'm uncertain about how to access and modify the ...

Responsive Design and the Importance of Setting Min-Width in Bootstrap 3

After doing some research on Stack Overflow about defining a minimum width for a responsive layout in Bootstrap3, I encountered conflicting answers related to "media queries." My goal is to make my layout responsive up to a certain point. Once it reaches, ...

Troubleshooting problem with GZIP in Angular 2 application deployment

I have developed an Angular 2 TypeScript application. I am using Firebase for hosting and Cloudflare for optimizing speed, caching, and security. When checking the browser header, it indicates: accept-encoding:gzip, deflate, sdch, br The app.js file has ...

Arrays in Javascript (correlating)

I'm having trouble figuring out what needs to be included in this code (I apologize that it's in German, it's an array corresponding to images for JavaScript.) function namenZuBildern(){ var bilder = new Array( "000227", "000228", " ...

The background of the wrapper div refuses to expand beyond the original size of the browser window

I'm currently in the process of developing a website, focusing on establishing the fundamental structure of my design to facilitate the addition of content and allow for the dynamic expansion of the div based on the length of the content. Nevertheless ...

Identify the current slide or div within a jQuery slideshow

I am currently facing an issue with my slide show that is composed of divs, each containing a picture and some html controls. The problem arises when clicking on a control in a slide other than the first one - it only updates the first slide. The only thin ...

Assistance needed for adjusting margins and padding within the inner content box

I'm currently in the process of designing a new website layout using CSS, but I've encountered some challenges along the way. My main goal is to ensure that all elements stay within the boundaries of the browser window, with the scroll bar appear ...

resizing: border box and height

I'm experimenting with a simple border box here, but the height of my box doesn't seem to be working as expected. * { box-sizing: border-box; } .div1 { width: 500px; height: 200px; border: 5px solid #E18728; float: left; } ...

Steps for attaching attributes to a displayed element in TileVectorLayer

As seen in the code below, I am creating a VectorTileLayer where the VectorTileSource is showing MVT geometry retrieved from a webservice specified in the url attribute. The database table includes columns as follows. The webservice will be called for each ...

The NodeJS namespace appears to be missing

I'm currently utilizing Ionic2 in conjunction with socket.io Upon running ionic serve, I encounter the following error message in the terminal: TypeScript error: typings/globals/socket.io/index.d.ts(357,30): Error TS2503: Cannot find namespace &apos ...

Wave your way to unique text creation with Firefox

Hey there, I've got some text inside a div that's been transformed with rotate(3deg). Strangely enough, in Firefox, the text appears wavy. When I remove the transform property from the div, the waviness disappears. Is there any way for me to keep ...

Incorporating DefinitelyTyped files into an Angular 2 project: A step-by-step guide

I am currently developing an application using angular 2 and node.js. My current task involves installing typings for the project. In the past, when starting the server and activating the TypeScript compiler, I would encounter a log with various errors rel ...

Connecting conversations in react

When working with jQuery, I often utilize the modal dialog chaining technique. For example: $.Deferred().resolve().promise() .then(function () { return runDialog1(someProps); // return promise }) .then(function (runDialog1Result) ...

Adding a button to the right of a text-field input in Vuetify app

I need advice on the best way to use Vuetify in order to display a button to the right of a text-field (attached). I've checked the main site for information but couldn't find anything related to this specific scenario. https://i.sstatic.net/Pp ...

FormArray in Angular fails to recognize the inputs for form controls in the last element

I am currently trying to create a FormArray with multiple FormGroups, but I am encountering a strange issue. The FormControls present in the last element of the FormArray are not accepting input values. add-modules.ts file import { ChangeDetectorRef, Comp ...

What is the best way to detect a change in a property using rxjs?

My Angular6 application has a simple input tag: <input type="text" name="searchBox" [(ngModel)]="searchTerm" class="form-control" /> I want to create an observable of the searchTerm property in order to apply operators like debounce, etc. How can I ...

What is the best way to sort a union based on the existence or non-existence of a specific

My API response comes in the form of a IResponse, which can have different variations based on a URL search parameter. Here is how I plan to utilize it: const data1 = await request<E<"aaa">>('/api/data/1?type=aaa'); const d ...