Saturday, November 3, 2012

how to change jqgrid row color

  how to change jqgrid row color

step1:create css stylesheet 

<style type="text/cs

 .myAltRowClass { background-color: #F08484; background-image: none; }
    </style>

Before jqgrid creation write the following function

   getColumnIndexByName = function (mygrid, columnName) {
        var cm = mygrid.jqGrid('getGridParam', 'colModel');
        for (var i = 0, l = cm.length; i < l; i++) {
            if (cm[i].name === columnName) {
                return i; // return the index
            }
        }
        return -1;
    };

Step2: on loadComplete: function () or gridcomplete function() wirite the following code


loadComplete: function () {
            var iCol = getColumnIndexByName($(this), 'del_columnname'),
                        cRows = this.rows.length, iRow, row, className;

            for (iRow = 0; iRow < cRows; iRow++) {
                row = this.rows[iRow];
                className = row.className;
   if ($.inArray('jqgrow', className.split(' ')) > 0) {                                                     
    var x = $(row.cells[iCol]).text();
                  
     if (x > 0) {
              if ($.inArray('myAltRowClass', className.split(' ')) === -1) {
                row.className = className + ' myAltRowClass';
                        }
                    }
                }
            }
        }



 Thats it!!!!

Another method :

on afterInsertRow: function () wirite the following code

 

afterInsertRow: function (rowid, rowdata) {

            var d = rowdata.del;

           

            if (parseInt(d) > 0) {
                $(this).jqGrid('setRowData', rowid, false, 'ui-state-error');


                $("#jqgrid").jqGrid('setRowData', rowid, false, 'StyleCss');

      }

        },

No comments:

Post a Comment