Please define a 'styler' function for the columns to display the background color.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>TreeGrid - jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/icon.css">
<script type="text/javascript" src="https://www.jeasyui.com/easyui/jquery.min.js"></script>
<script type="text/javascript" src="https://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
<script>
var data = {
"total": 7, "rows": [
{ "id": 1, "name": "All Tasks", "begin": "3/4/2010", "end": "3/20/2010", "progress": 60, "iconCls": "icon-ok" },
{ "id": 2, "name": "Designing", "begin": "3/4/2010", "end": "3/10/2010", "progress": 100, "_parentId": 1, "state": "closed" },
{ "id": 21, "name": "Database", "persons": 2, "begin": "3/4/2010", "end": "3/6/2010", "progress": 100, "_parentId": 2 },
{ "id": 22, "name": "UML", "persons": 1, "begin": "3/7/2010", "end": "3/8/2010", "progress": 100, "_parentId": 2 },
{ "id": 23, "name": "Export Document", "persons": 1, "begin": "3/9/2010", "end": "3/10/2010", "progress": 100, "_parentId": 2 },
{ "id": 3, "name": "Coding", "persons": 2, "begin": "3/11/2010", "end": "3/18/2010", "progress": 80 },
{ "id": 4, "name": "Testing", "persons": 1, "begin": "3/19/2010", "end": "3/20/2010", "progress": 20 }
], "footer": [
{ "name": "Total Persons:", "persons": 7, "iconCls": "icon-sum" }
]
}
function styler(value,row){
const field = this.field;
return (row['style']||{})[field];
}
$(function(){
$('#tg').treegrid({
onClickCell: function(field,row,index){
row['style'] = row['style']||{}
row['style'][field] = 'background:red;color:#fff';
$(this).treegrid('refreshRow',row['id'])
}
})
})
</script>
</head>
<body>
<table id="tg" title="TreeGrid" style="width:700px;height:250px" data-options="
iconCls: 'icon-ok',
rownumbers: true,
animate: true,
collapsible: true,
fitColumns: true,
data: data,
idField: 'id',
treeField: 'name'
">
<thead>
<tr>
<th data-options="field:'name',width:180,styler:styler">Task Name</th>
<th data-options="field:'persons',width:60,align:'right',styler:styler">Persons</th>
<th data-options="field:'begin',width:80,styler:styler">Begin Date</th>
<th data-options="field:'end',width:80,styler:styler">End Date</th>
</tr>
</thead>
</table>
</body>
</html>