الجمعة، 28 نوفمبر 2014

How to colorize a grid rows in CRM 2011 & 2013

1- Write the following JS code:
function ColorizeGridRows() {
    //debugger;
    var StatusField_index = 0;
    
    var iColumns = 0;
    if (window.document.getElementById('gridBodyTable') != null) {
        var gridBar = window.document.getElementById('gridBodyTable');
        if (gridBar != null && gridBar != "undefined") {
            var headers = gridBar.getElementsByTagName('TH');
            //Total no. of columns in the view
            iColumns = headers.length;
            for (var index = 0; index < headers.length; index++) {
                var header = headers[index];
                switch (header.innerText) {
                    case "Status Reason":
                        StatusField_index = index;
                        break;
                    default:
                        break;
                }
            }
        }
        if (StatusField_index != 0) {
            //Get the Grid records
            var GridCtrl = window.document.getElementById('gridBodyTable');
            _iTotalRecords = GridCtrl.rows.length - 1;
            //GridCtrl.rows[0].style.display = 'none';
            for (var i = 1; i < GridCtrl.rows.length; i++) {
                var cellStatus = GridCtrl.rows[i].cells[StatusField_index];
                if (cellStatus != null) {
                    if (cellStatus.innerText == "Accepted") {
                        GridCtrl.rows[i].style.backgroundColor = 'green';
                    }
                    else if (cellStatus.innerText == "Rejected") {
                        GridCtrl.rows[i].style.backgroundColor = 'red';
                    }
                }
            }
        }
    }
}


2- Add the Above JS code to web Resource and add the web resource to entity form.
3- Add button to Main Grid ribbon called "Colorize Grid".
4- Set the Enabled rule for this button to JS function as below:


ليست هناك تعليقات:

إرسال تعليق