Style a single cell using ng-grid with Angular 6

ag-grid cell style
ag-grid change row style dynamically
ag-grid header background color
ag-grid cell border color
ag-grid group row style
ag-grid cell renderer
ag-grid cellstyle not working
ag-grid checkbox style

I am trying to access a single cell on an ag-grid using Angular 6. The html looks like this:

 <ag-grid-angular 
 style="width: 700px; height: 200px;" 
 class="ag-theme-balham"
 [rowData]="rowData" 
 [columnDefs]="columnDefs"
 rowSelection="single"
 colDef.editable=true
 (gridReady)="onGridReady($event)"
 >
 </ag-grid-angular>

the typescript class is:

 ngOnInit( ) {

  }
  onGridReady(params){
    this.gridApi = params.api
    this.columnApi =  params.columnApi
  }
  updateRow(){
    var rowNode = this.gridApi.getRowNode(0);
    rowNode.setData(
      { make: 'changed', model: 'changed', price: 10 },
    )

  }
  updateCell(){
    var rowNode = this.gridApi.getRowNode(0);
    this.gridApi.getRowNode(0)
    rowNode.setDataValue("model","mobile")
  }
  addColumn(){
    var rowNode = this.gridApi.getRowNode(0);
    var x = parseInt(rowNode.data.price)
    var rowNode = this.gridApi.getRowNode(1);
    var y = parseInt(rowNode.data.price)
    var rowNode = this.gridApi.getRowNode(2);
    var z = parseInt(rowNode.data.price)
   console.log("price", x ,y, z)
   this.total = x+y+z


  }

  columnDefs = [
   // use this for the whole column   {headerName: 'Make', field: 'make',cellStyle: {  'border-bottom': '3px double'} },
   {headerName: 'Make', field: 'make',cellStyle: {
    // you can use either came case or dashes, the grid converts to whats needed
    backgroundColor: '#aaffaa' // light green
}},
    {headerName: 'Model', field: 'model'},
    {headerName: 'Price', field: 'price', editable: true},
    {headerName: '', field: '', editable: true}
];

rowData = [
    { make: 'Toyota', model: 'Celica', price: 35000, cellClass: "col-1" },
    { make: 'Ford', model: 'Mondeo', price: 32000 },
    { make: 'Porsche', model: 'Boxter', price: 72000 }
];

i can target a column using cellstyle but i only want to add borders to each cell. Is it possible to target a cell like i have done using:

var rowNode = this.gridApi.getRowNode(1);

and add a style to the rowNode or is there another way to achieve this?

According to the documentation you should be able to apply styles to an individual cell by passing the param as below or you can use cellClassRules.

  columnDefs = [
   // use this for the whole column   {headerName: 'Make', field: 'make',cellStyle: {  'border-bottom': '3px double'} },
   {headerName: 'Make', field: 'make',cellStyle:function(params) {
    // you can use either came case or dashes, the grid converts to whats needed
//Style the specific cell with one class and the whole column with another
return (params.colDef===1?'my-class-1':'my-class-2');
}},
    {headerName: 'Model', field: 'model'},
    {headerName: 'Price', field: 'price', editable: true},
    {headerName: '', field: '', editable: true}
];

Core feature of ag-Grid supporting Angular, React, Javascript and more. One such feature is Cell Styling. Use CSS rules to define Cell Style based on data content, e.g. put a red background onto cells that have negative values, and green on values Angular. ng-Conf. Postponed. ngVikings. Postponed. Angular Connect. Version 23 onwards of ag-grid-angular / @ag-grid-community/angular will support Angular 6+ only. ag-Grid is the industry standard for Angular Enterprise Applications. Developers using ag-Grid are building applications that would not be possible if ag-Grid did not exist.

i found that if i use this

{headerName: 'Model', field: 'model',cellClass:function(params) {
  console.log("params ", params);
  console.log("params value", params.value);
  console.log("params colDef", params.node.rowIndex);
  // you can use either came case or dashes, the grid converts to whats needed
//Style the specific cell with one class and the whole column with another
return (params.node.rowIndex===1?'my-class-1':'my-class-2')}},

and you need to place the css in styles.css as its not working in the components css file. I can target the individual cell.

Hi, is it possible to have a specific class for an individual cell but NOT be based For example, I might be refreshing the data often in the grid and cell 6 to have the font color "red" while for example row 6, cell 6 to be "blue". The object literal syntax is better for when you want to set multiple classes or styles in one statement. The shortcut syntax, [style|class.<property>], is better for setting a single class or style.

If you just want to add the border on each cell then you can just simple css solution for this -

.ag-cell {
    border: solid 1px blue !important;
}

If you want to add the border for selected cell only then you can use -

 .ag-cell-focus {
        border: solid 1px blue !important;
    }

Grid Conditional Cell Styling. The IgxGrid component in Ignite UI for Angular provides two ways to conditional styling of cells based on custom rules. The result is a convenient material styling of the cell. Use ::ng-deep or ViewEncapsulation. If there are cells bind to the same condition (from different columns) and one  There are many plugins from third-parties that can be integrated into AngularUI Pages, but ng-grid exists inside the AngularJs framework and is very rich in functionality and compatibility. Let us create a sample ng-grid and understand how ng-grid works. Example-1

Configure in cell data manipulation with feature rich Angular UI grid, try the update data features and Angular CRUD by using the Ignite UI for Angular grid editing. You can enter edit mode for specific cell, when an editable cell is focused in one To do this, you need to pass an ng-template with the igxCellEditor directive  Thanks, I'm actually using that now to define that numbers should be right align etc.. however, there is a need for example to have row 5, cell 6 to have the font color "red" while for example row 6, cell 6 to be "blue". This will change dynamically. I was looking for a way to specify the CSS class on an individual cell by cell basis rather

Get started with the Angular Grid by Kendo UI which allows you to style the appearance of The Grid enables you to style its columns, rows, and cells. Customizing the rendering of columns; Setting the background for specific columns <ng-template kendoGridCellTemplate let-dataItem> <span class="​whole-cell" [style. Cell Style: Providing a CSS style for the cells. Cell Class: Providing a CSS class for the cells. Cell Class Rules: Providing rules for applying CSS classes. Each of these approaches are presented in the following sections. Cell Style. Used to provide CSS styles directly (not using a class) to the cell.

This article explains the usage of ng-grid in AngularJS. It is a common requirement for any project to display data in a tabular format. using HTML tables, but soon this gets complex, you need a way to support sorting (single & multi columns), resizable editCell = function (row, cell, column) {; $scope. Ranges can overlap but only one class, event function, format function etc is activated on a single cell. The order of precedence is the same as the order of the range declarations. The callback receives the cell and the cellData.

Comments
  • I have tried the function but there is no change. does the function need the params to be passed?
  • when i print the params.colDef i get params colDef {headerName: "Model", field: "model", cellStyle: ƒ} cellStyle: ƒ (params) field: "model" headerName: "Model" proto: Object
  • Any of these methods should be helpful ag-grid.com/javascript-grid-cell-styles
  • it will work in component.css once you will add the encapsulation
  • Any of these methods should be helpful ag-grid.com/javascript-grid-cell-styles
  • I would suggest to better use ag-grid built-in mecahnisms, have a look at this Any of these methods should be helpful ag-grid.com/javascript-grid-cell-styles