1. 程式人生 > >【easyui】 datagrid動態改變某一行的顏色

【easyui】 datagrid動態改變某一行的顏色

直接上程式碼:

$(function () {
            dataGridAccept = $('#dataGridAccept').datagrid({
                fit: true,
                fitColumns: false,
                border: false,
                pagination: false,
                idField: 'id',
                striped: true,
                remoteSort: false
, pageSize: 20, pageList: [5, 10, 20, 80, 100], sortOrder: 'asc', singleSelect: true, checkOnSelect: true, selectOnCheck: true, nowrap: true, showPageList: false, enableRowContextMenu: false
, url: "${pageContext.request.contextPath}/match.do", columns: [[{ field: 'id', title: '丟擲ID', width: 100, align: 'center', sortable: false, hidden: true
}, { field : 'del', title : '是否終止', width : 100, align:'center', sortable : false, hidden:false }]], toolbar: '#toolbar', onLoadSuccess: function () { $(this).datagrid('tooltip'); $(this).datagrid('clearSelections'); }, rowStyler: function (index, row) { if(row.del=='1'){ return 'background-color:red;'; } }, onClickRow: function (index, row) { } }); });

關鍵程式碼:

rowStyler: function (index, row) {
                    if(row.del=='1'){
                        return 'background-color:red;';
                    }

                }

這裡就可以了~