Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6121023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:44:11+00:00 2026-05-23T15:44:11+00:00

jqGrid has column named Posted. It can be positioned in different positions depending how

  • 0

jqGrid has column named Posted. It can be positioned in different positions depending how grid is configured by customer but is always prssent.

I need to change background color of rows if Posted column has value True

I tried colmodel below but alert(rdata.Posted) displays always undefined.

How to change backgound color of row if Posted column in this row has value true ?

I looked into lot of Oleg and other solutions for changing background color but they are using hard coded column number.

colModel: [

{"cellattr":function(rowId, tv, rawObject, cm, rdata) {  
if (rdata.Posted)
    return 'class="jqgrid-readonlycolumn"';
    return '';
      }
  ,"label":"Klient","name":"Klient_nimi","classes":null,"hidden":false},


{"label":null,"name":"Posted","editable":true,"width":0,
"classes":null,"hidden":true}],
...

Update

In update2 Oleg recommends to use rowattr. I need to hide inlined delete button and custom post button in actions column also. I’m usijng code below in loadComplete. How to implement this using rowattr ?

var LoadCompleteHandler = function () {
    var iCol = getColumnIndexByName($grid, 'Kinnitatud'),
      postedDateCol = getColumnIndexByName($grid, 'Kinkuup'),
      cRows = $grid[0].rows.length,
      iRow,
      row,
      className,
      isPosted,
      mycell,
      mycelldata,
      i, count,
      cm = $grid.jqGrid('getGridParam', 'colModel'),
      l,
      iActionsCol = getColumnIndexByName($grid, '_actions');
    l = cm.length;
    if (iCol > 0 || postedDateCol > 0) {
        for (iRow = 0; iRow < cRows; iRow = iRow + 1) {
            row = $grid[0].rows[iRow];
            className = row.className;
            isPosted = false;
            if ($.inArray('jqgrow', className.split(' ')) > 0) { // $(row).hasClass('jqgrow')
                if (iCol > 0) {
                    isPosted = $(row.cells[iCol]).find(">div>input:checked").length > 0;
                }
                if (postedDateCol > 0) {
                    mycell = row.cells[postedDateCol];
                    mycelldata = mycell.textContent || mycell.innerText;
                    isPosted = mycelldata.replace(/^\s+/g, "").replace(/\s+$/g, "") !== "";
                }

                if (isPosted) {
                    if ($.inArray('jqgrid-postedrow', className.split(' ')) === -1) {
                        row.className = className + ' jqgrid-postedrow';
                        $(row.cells[iActionsCol]).find(">div>div.ui-inline-del").hide();
                        $(row.cells[iActionsCol]).find(">div>div.ui-inline-post").hide();
                    }
                }
            }
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:44:12+00:00Added an answer on May 23, 2026 at 3:44 pm

    The main ideas to change the background color of the row you will find here and here. I recommend you to read this answer which discussed different advantages and disadvantages of different approaches.

    To get column index from the column name you can use following simple function:

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

    The function getColumnIndexByName($("#list"), 'MyColumnName') will get you the index in colModel of the ‘MyColumnName’ column.

    To change the background color you can follow the example

    loadComplete: function() {
        $("tr.jqgrow:odd").addClass('myAltRowClass');
    }
    

    from the answer, but instead of ':odd' filter you can write the filter yourself using jQuery.filter. Inside of the filter you can use :nth-child() to access the data from the corresponding <td> element (see here)

    UPDATED: You can do the following (very close to the code from the another answer):

    loadComplete: function() {
        var iCol = getColumnIndexByName($(this),'closed'),
            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]).children("input:checked");
                if (x.length>0) {
                    if ($.inArray('myAltRowClass', className.split(' ')) === -1) {
                        row.className = className + ' myAltRowClass';
                    }
                }
            }
        }
    }
    

    The corresponding demo is here. You will see the following:

    enter image description here

    By the way if the ‘Closed’ column will be hidden everything will continue to work as before.

    UPDATED 2: The answer describe how to use rowattr callback to simplify the solution and to have the best performance (in case of gridview: true).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone been able to customize jQGrid? While I'd like something easy I can
Has anyone been able to implement the JQuery grid plugin, jqGrid? I'm trying to
I have a jqgrid where the database table has a few thousand rows, but
My jqGrid is showing (1303153262000) on the initial grid load. However when the column
jqGrid has a column chooser functionality as like described here: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:jquery_ui_methods and a demonstration
I need to develop a grid using jqGrid and PHP what has 4 columns:
I have a jqGrid on a page and users can click a button to
I'm trying to create a jqgrid, but the table is empty. The table renders,
I have seen the following demo with frozen column and filter toolbar here: http://www.ok-soft-gmbh.com/jqGrid/FrozenColumns.htm
I'm initializing the grid like so: $(#mainGrid).jqGrid({ url : g_MainGridUrl, datatype : 'json', height

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.