Hello,
Thanks for your remark for the prefix
Here is the code I use from your original example.
{
"height": 200,
"selectableRows": true,
"layout":"fitColumns",
"rowFormatter": "@F:myRowFormatter",
"data": [
{
"id": 1,
"fname": "John",
"lname": "Smith",
"age": 25,
"gender": "Male ",
"clr": 3,
"notes": "A jolly good fellow"
},
{
"id": 2,
"fname": "Jack",
"lname": "Brown",
"gender": "Male ",
"age": 9,
"clr": 4,
"notes": "Just a little boy"
},
{
"id": 3,
"fname": "Jill",
"lname": "Baker",
"gender": "Female",
"age": 21,
"clr": 5,
"notes": "She's the best"
}
],
"columns": [
{"formatter":"rowSelection","titleFormatter":"rowSelection","width": 40,"hozAlign":"center","headerSort":false},
{
"title": "Id",
"field": "id",
"width": 50,
"headerSortTristate":true,
"hozAlign": "center"
},
{
"title": "First Name",
"field": "fname",
"width": 120,
"headerSortTristate":true,
"hozAlign": "left",
"headerFilter": "input",
"headerFilterPlaceholder": "Filter..."
},
{
"title": "Last Name",
"field": "lname",
"width": 120,
"headerSortTristate":true,
"hozAlign": "left",
"headerFilter": "input",
"headerFilterPlaceholder": "Filter..."
},
{
"title": "Gender",
"field": "gender",
"width": 100,
"headerSortTristate":true,
"hozAlign": "center",
"editor": "list",
"editorParams": {
"values": {
"Male ": "Male ",
"Female": "Female",
"Unknown": "Unknown"
}
},
"headerFilter": true,
"headerFilterPlaceholder": "Select...",
"headerFilterParams": {
"values": {
"Male ": "Male ",
"Female": "Female",
"Unknown": "Unknown",
"": ""
}
}
},
{
"title": "Age",
"field": "age",
"headerSortTristate": true,
"hozAlign": "center",
"formatter": "@F:ageColor",
"formatterParams": {
"minAge": 18
}
},
{
"field": "clr",
"width": 20,
"headerSortTristate":true,
"hozAlign": "center",
"formatter": "traffic",
"formatterParams": {
"min": 0,
"max": 6,
"color": [
"",
"gray",
"orange",
"blue",
"green",
"red",
"cyan"
]
}
},
{
"title": "Notes (Editable)",
"field": "notes",
"headerSortTristate":true,
"hozAlign": "left",
"editor": "input"
}
]
}
Custom Functions:
// Conditional formatter
//function ageColor(cell, params) {
// if (cell.getValue() < params.minAge)
// cell.getElement().style.color = 'orange';
// return cell.getValue();
//}
function ageColor(cell) {
if (cell.getValue() > 20)
cell.getElement().style.color = 'orange';
return cell.getValue();
}
function myRowFormatter(row) {
var data = row.getData();
if (data.id == 1) {
row.getElement().style.backgroundColor = "red";
}
}
Here is the result I expected:
Uploading: image.png…