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

  • SEARCH
  • Home
  • 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 7029379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:31:53+00:00 2026-05-28T00:31:53+00:00

i am using jqGrid treegrid and i want to format the back color of

  • 0

i am using jqGrid treegrid and i want to format the back color of columns based on the value of the data in the cell (its an integer):

Here is an example where I setup the column:

             {
                 name: 'missingBooks',
                 cellattr: function (rowId, tv, rawObject, cm, rdata) {

                 //conditional formatting
                     if (rawObject[11] > 0) {
                         return 'style="background-color:#FFCCCC"';
                     }
                 },
                 width: 75,
                 unformat: originalValueUnFormatter,
                 formatter: missingBooksFormatter,
                 align: "right",
                 index: 'missingBooks',
                 hidden: false,
                 sorttype: 'int',
                 sortable: true
             },

this works fine but my issue is in the cellAttr callback. In this conditional formatting line:

      if (rawObject[11] > 0) {
                         return 'style="background-color:#FFCCCC"';
                     }

i would like to reuse this logic so i dont want to have to index into the rawObject and figure out what column i am using. i was hoping there was a way to do something like this:

       if (rawObject.missingBooks > 0) {
                         return 'style="background-color:#FFCCCC"';
                     }

but this seems to be undefined. This way if i add a new column i dont have to reindex all of this conditional formatting code.

  • 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-28T00:31:53+00:00Added an answer on May 28, 2026 at 12:31 am

    I understand the problem. I suggested Tony to make some changes in jqGrid code. Mostly it would be enough to modify the place in the code to fill first rd and then in the next for loop call addCell with rd as additional parameter. The function addCell could forward the information to formatCol and the formatCol can call cellattr with additional parameter rd which will be has the information in exact the same format like you as want.

    Nevertheless one can relatively easy to have almost the same results which you need without any changes in the jqGrid code. To do this one can just construct the map object which can give us the index of the column in the rawObject based on the name.

    For example we can use beforeRequest or beforeProcessing to fill the map if it is not yet filled. The code can looks like

    var colMap = {};
    $("#tree").jqGrid({
        ...
        colModel: [
            {name: 'missingBooks',
                cellattr: function (rowId, tv, rawObject, cm, rdata) {
                    //conditional formatting
                     if (Number(rawObject[colMap.missingBooks]) > 0) {
                         return ' style="background-color:#FFCCCC"';
                     } else {
                         return '';
                     }
                }
                ...
        ],
        beforeRequest: function () {
            if ($.isEmptyObject(colMap)) {
                var i, cmi,
                    cm = $(this).jqGrid('getGridParam', 'colModel'),
                    l = cm.length;
                for (i = 0; i < l; i++) {
                    cmi = cm[i];
                    colMap[cmi.name] = i;
                }
            }
        }
    });
    

    So the code will be free from usage of indexes like rawObject[11] where the index 11 can be changed after some modification in the code.

    You can see the corresponding demo here.

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

Sidebar

Related Questions

I'm using jqgrid. I need to set background color of the cell based on
I am having trouble constructing a jqGrid TreeGrid using local data. This method works
I am using a jqgrid's treegrid and the data for the child nodes is
I am using jqGrid to render some data. Now I want the ability to
I am using jqgrid treegrid to load the data remotely on expand event. It
Using jqGrid I want to open a cell-editor on double-click , so my code
I am using jqGrid with treeGrid. I have added a filterToolbar. I would like
I am using treegrid with jqGrid and am quite new to this plugin. I
I am using jqGrid ( http://www.trirand.com/blog/ ) to display some read-only data. The resizeable
jqGrid tree nodes are read from server using json data. Click in node reads

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.