Hi,
I am trying to implement something like this, where the style is set in the itemformatter method.The issue is itemformatter is not being invoked.
My Template
wj-flex-grid #flex headersVisibility=1 [itemFormatter]="itemFormatter" [itemsSource]="dataCollection" [allowSorting]="allowSorting" [selectionMode]="selectionMode"
[allowDragging]="allowDragging">
<wj-flex-grid-column *ngFor="let column of columnDefCollection" [header]="column.header" [binding]="column.binding" [width]="115"
[isReadOnly]="!column.editable">
<template wjFlexGridCellTemplate [cellType]="'Cell'" *ngIf="column.isCustomCellTemplate" let-item="item">
<!--<wj-list-box #listBox style="height:150px;width:110px;" [itemsSource]="listBoxItemsSource">
</wj-list-box>-->
<p><input type="checkbox" [(ngModel)]="item.active" /></p>
</template>
</wj-flex-grid-column>
</wj-flex-grid>
<input type="button" (click)="GetSelectedRows()" value="Get Selected Rows" />
TS File
import { Component, OnInit, ViewChild, ViewEncapsulation } from "@angular/core";
import { WjGridModule, WjFlexGrid } from "wijmo/wijmo.angular2.grid";
import { WjListBox } from "wijmo/wijmo.angular2.input";
import * as wjcCore from "wijmo/wijmo";
import * as wjcGrid from "wijmo/wijmo.grid";
import * as wjcInput from 'wijmo/wijmo.input';
import { GridDataService } from "./gridData.service";
import { Constants } from "../constants";
@Component({
selector: 'grid',
templateUrl: './grid.component.html',
styleUrls: ['./grid.component.scss'],
providers: [GridDataService],
encapsulation: ViewEncapsulation.None
})
export class GridComponent implements OnInit {
@ViewChild('flex') flex: WjFlexGrid;
@ViewChild('listBox') listBox: WjListBox;
private dataCollection: any;
private columnDefCollection: any;
private errorMessage: string;
private countries: Array<any>;
private selection: Array<any>;
private dataEndpoint: string = Constants.GRID_DATA_ENDPOINT;
//Grid options:
allowSorting: boolean = true;
selectionMode: string = "RowRange"; //None, Cell, CellRange, Row, RowRange, ListBox
allowDragging: string = "Both"; //None, Rows, Columns, Both
constructor(private gridDataService: GridDataService) {
}
ngOnInit() {
this.setData(this.dataEndpoint);
this.setColumnDef(this.dataEndpoint);
}
setData(endpoint): void {
this.gridDataService.getData(endpoint).subscribe(
rowData => {
console.log(rowData)
this.dataCollection = rowData.itemInfoList;
},
error => {
this.errorMessage = <any>error
console.log(this.errorMessage);
}
);
}
setColumnDef(endpoint): void {
// {
// nodeid: 1206,
// indexed: true,
// displayname: "ID",
// path: "id",
// editable: true,
// attrType: "String"
// }
var columns = []
let checkboxColumn = {
"header": "",
"dataType": wjcCore.DataType.Boolean,
"binding": "",
"editable": false,
"pinned": "left",
"isCustomCellTemplate": true
}
columns.push(checkboxColumn);
this.gridDataService.getData(endpoint).subscribe(
columnDef => {
var columnDefination = columnDef.attrInfoList;
for (var index in columnDefination) {
var column = {}
column["header"] = columnDefination[index].displayname;
column["binding"] = columnDefination[index].nodeid;
column["editable"] = columnDefination[index].editable;
columns.push(column);
}
console.log(columns);
this.columnDefCollection = columns;
},
error => {
console.log(error);
console.log("here");
this.errorMessage = <any>error
}
);
}
GetSelectedRows() {
this.selection = [];
// for (var i = 0; i < 100000; i++) {
// if (this.dataCollection[i%this.dataCollection.length].selected == true) {
// this.selection.push(i);
// }
// }
console.log(this.selection.length);
}
setSelected(flex: wjcGrid.FlexGrid, e: wjcGrid.FormatItemEventArgs) {
for (var index in flex.selectedRows){
flex.selectedRows[index].cssClass = "row_selected";
}
}
itemFormatter=(panel,r,c,cell)=>{
console.log("Here in Item Formatter")
var rows=panel.rows[r];
if(rows.dataItem.active){
cell.style.backgroundColor='blue';
}
}
formatItem(flex: wjcGrid.FlexGrid, e: wjcGrid.FormatItemEventArgs) {
// add/ handle check box in columnheader
// if (e.panel.cellType == wjcGrid.CellType.Cell) {
// var row = flex.rows[e.row];
// if (row.dataItem.selected) {
// e.cell.classList.add("row_selected");
// }
// else{
// e.cell.classList.remove("row_selected");
// }
// }
}
}
So, if something is selected from the data source when it is laoded, it is marked as blue background. But after when i manually select, it does not work.