Shading rows based on a specific field value in the Angular UI Grid

Is it possible to color rows based on their field values in the latest angular-ui-grid when all columns are generated dynamically and row selection is enabled?

I have come across suggestions to use a rowTemplate for this purpose. Here is an example of a row template that I am trying to implement:

rowTemplate:'<div ng-class="{ \'grey\':row.entity.Locked=="True" }"> <div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell" ng-class="{ "ui-grid-row-header-cell": col.isRowHeader }"  ui-grid-cell></div></div>'

The goal is to color a row grey if the value in the "Locked" column is set to "True". However, this approach does not seem to be working as expected. Is the row template correct or is there a better way to achieve this functionality?

$scope.gridOptions={
    showGridFooter: true,
    data:'myData',
    paginationPageSizes: [10, 15, 20],
    paginationPageSize: 10,
    enableColumnResizing: true,
    rowTemplate:'<div ng-class="{ \'grey\':row.entity.Locked=="True" }"> <div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell" ng-class="{ "ui-grid-row-header-cell": col.isRowHeader }"  ui-grid-cell></div></div>',


onRegisterApi : function(gridApi){

// Set gridApi on scope
$scope.gridApi = gridApi;

// Getting Selected rows
gridApi.selection.on.rowSelectionChanged($scope,function(row){
var msg = 'row selected ' + row.isSelected;
console.log(msg);
$scope.mySelectedRows= $scope.gridApi.selection.getSelectedRows();  
console.log( $scope.mySelectedRows);

});

}
};

$http.get('WS/datareserve').success(function(data){
$scope.myData=data;
console.log( $scope.myData);

angular.forEach(data[0], function(value, key){

if(key=="Locked"){
$scope.gridOptions.columnDefs.push({ field: key, displayName: "LOCKED", width: 150});
}

else{
$scope.gridOptions.columnDefs.push({ field: key, displayName: key, width: 150});
}

});

}).error(function(data){
console.log("Request failed "+ $scope.gridOptions.data);
});

Answer №1

Your code snippet is correct, as the cell's style is controlled by the .ui-grid-cell-contents class. You can customize it in your template as shown below.

.custom-style .ui-grid-cell-contents
{
  background-color: blue;
}

For a visual example, check out this link http://plnkr.co/edit/RAvE573NjhQFTzx28dKU?p=preview

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

Transitioning to TypeScript has brought the promise of imports returning once again

I've been facing some challenges while migrating my extensive project to TypeScript, particularly with handling imports. Being relatively new to programming, I'm unsure if my previous approach was considered bad practice. Previously, I organized ...

Is there a way to make an iPhone Select List that only allows for a single selection instead of multiple

I seem to be encountering a problem where the select dropdowns on my iPhone, bound in knockout, are allowing users to select multiple items. The select scrollwheel pops up and I'm wondering if there's a way to make it only allow single values. Be ...

Animating objects in ThreeJS to traverse multiple positions smoothly with linear interpolation (lerp)

I am exploring ways to animate a sphere's movement along a predefined sequence of vertices. I have successfully managed to animate the sphere from one point to another using the code below: function animate() { requestAnimationFrame(animate) spher ...

Exclude the extended type of generics in TypeScript

I'm encountering an issue with omit in typescript. Whenever I attempt to omit commandId from TMutationVariables, it triggers a TS error: TS2345: Argument of type 'Pick<TMutationVariables, Exclude<keyof TMutationVariables, "commandId">&g ...

Display two images consecutively within a single img tag

My goal is to display two images using a single <img /> tag. The first small image will be loaded and shown using the src attribute, while the second large image will be contained within the data-src attribute. Only one image will be displayed at a t ...

Tips for intentionally refreshing or crashing a browser tab by utilizing the response from an AJAX request

Yesterday, we deployed new code to our production environment which included a polling mechanism using setInterval() in Javascript. This feature makes an AJAX request every 15 seconds to update clients with the server. Surprisingly, even though only around ...

Karma is reporting an error with TypeScript, saying it cannot locate the variable 'exports'

Currently, I am in the process of mastering how to write Unit Test cases for an angular project coded in Typescript. To facilitate this, I have opted for utilizing Karma and Mocha. Below lays out the structure of the application: Project/ ├── app/ ...

How to stop a checkbox from being selected in Angular 2

I have a table with checkboxes in each row. The table header contains a Check All checkbox that can toggle all the checkboxes in the table rows. I want to implement a feature where, if the number of checkboxes exceeds a certain limit, an error message is ...

Getting your JQuery ready() statement right is crucial for the proper

I have come across all three variations below: $().ready(); $(document).ready(); $(document.body).ready(); All of them seem to work, but I'm wondering which one is the most appropriate or recommended to use when considering the usage of the ready() ...

Why is my Laravel function retrieving outdated session data?

Currently, I am in the process of developing a shopping cart feature using session. My goal is to create a function that can update the quantity of an item in the shopping cart and refresh both the subtotal and the list of items in the cart displayed on th ...

Function on NextJS site failing to adhere to the two-second timeout limit

I have implemented an 'image slide show' that switches between images every two seconds by toggling their display types from "none" to "block". Within my .js file, the showSlides function is declared at the top: var slideIndex = 0; function sho ...

Problem Encountered with Jquery Validation for Name Field (Restriction to Alphabetic

I am struggling to validate a name format using a predefined jQuery validation tool. My intention is for the name field to accept only characters, but even with the correct regex pattern, it still allows numbers to be entered. The specific script I am us ...

Retrieve information from the database and showcase it in a competitive ranking system

Here is the HTML and CSS code for a leaderboard: /* CSS code for the leaderboard */ To display the top 5 in the leaderboard, PHP can be used to fetch data from the database: <?php // PHP code to retrieve data from the database ?> The current ou ...

Tips for smoothly transitioning between tabs in IONIC by simply clicking on a link or url

Imagine having two tabs within my application: tab-one and tab-two. I am trying to navigate from the view of tab-one (one.html) to the view of tab-two (two.html). I have attempted using $state.go(), $location, and $window.location but none of them seem t ...

Guide for displaying retrieved information on a Bootstrap Modal window following data submission in Yii2

I'm encountering an issue with a Modal popup that contains two fields. The first field is used to submit information and perform an internal database query, while the second field should display the returned data. Oddly enough, when testing the functi ...

"JS Kyle: Utilizing JWT for Signing and Encrypting Data

I am currently using jose for signing and encrypting JWTs, but I am facing an issue when trying to sign and then encrypt the entire JWT. When it comes to signing my JWT, I utilize the following function: const secretKey = process.env.JWT_SECRET; const key ...

Using JavaScript to open a window in ASPX page

When I use the code below to open a new window and receive a success message, I also want to close the current window. However, I am encountering an error: Error: newwindow is not defined var value = getQueryStrings(); var cust_id = value["cust_id ...

Leveraging JSON Data for Dynamic Web Content Display

I have been attempting to parse and display the JSON data that is returned from a REST API without any success. When tested locally, the API's URL structure is as follows: http://localhost/apiurl/get-data.php It returns data in the following format ...

Experience the potential of HTML5 by playing dual audio MKV/AVI videos

After conducting some research, it seems that Chrome has the necessary codecs to play MKV videos. However, I have yet to come across any information on how to select audio tracks in MKV and AVI files using Javascript/HTML5. Does anyone have any insight in ...

Break up every word into its own separate <span>

I am currently facing an issue with displaying an array of strings in HTML using spans. These spans are wrapped inside a contenteditable div. The problem arises when a user tries to add new words, as the browser tends to add them to the nearest existing sp ...