Transform the Background Colors of certain Column Headers in a jqGrid Table

I have tried to implement the solution suggested in this post, but unfortunately, it did not work for me: jqGrid change background color of specific column headers

Even after trying various CSS entries, I still couldn't get the color to change to yellow as desired.

.ui-jqgrid-htable .ford {
    background-color: yellow !important;
    background-image: none;
}

.ui-jqgrid .ui-jqgrid-htable  .ford {
    background-color: yellow !important;
    background-image: none;
}

.ui-jqgrid .ui-jqgrid-htable  th.ui-th-column-header .ford {
    background-color: yellow !important;
    background-image: none;
}

.ui-jqgrid .ui-jqgrid-htable .ui-jqgrid-hbox .ford {
    background-color: yellow !important;
    background-image: none;
}

.ui-jqgrid .ui-jqgrid-htable th .ford {
    background-color: yellow !important;
    background-image: none;
}

This is how I set up the grid:

$('#list').jqGrid({
    url: "/User/GetGridData",
    mtype: "GET",
    datatype: "json",
    colNames: ['', 'ID', 'Name', 'Email', 'ford Browser', 'ford Team', 'ford Director', 'chevy Browser', 'chevy Editor','chevy Team','Tool Admin',''],
    colModel: [
        { name: 'edit', index: 'edit', width: 5, sortable: false, search: false, formatter: editRow },
        { name: 'id', index: 'id', width: 1, hidden: true, editable: false, key: true },
        { name: 'userName', index: 'userName', width: 75, align: 'left', editable: true, searchoptions: { sopt: ['eq', 'cn'] } },
        { name: 'userEmail', index: 'userEmail', width: 100, align: 'left', editable: true, search: false  },
        { name: 'fordBrowser', index: 'fordBrowser', classes: 'ford', width: 35, align: 'center', editable: true, searchoptions: { sopt: ['eq', 'cn'] }, formatter: checkboxFormatter, formatoptions: { disabled: false } },
        { name: 'fordTeam', index: 'fordTeam', classes: 'ford',  width: 35, align: 'center', editable: true, searchoptions: { sopt: ['eq', 'cn'] }, formatter: checkboxFormatter, formatoptions: { disabled: false }},
        { name: 'fordDirector', index: 'fordDirector',classes: 'ford', width: 35, align: 'center', editable: true, searchoptions: { sopt: ['eq', 'cn'] }, formatter: checkboxFormatter, formatoptions: { disabled: false }},
        { name: 'chevyBrowser', index: 'chevyBrowser', classes: 'chevy' , width: 35, align: 'center', editable: true, searchoptions: { sopt: ['eq', 'cn'] }, formatter: checkboxFormatter, formatoptions: { disabled: false }},
        { name: 'chevyEditor', index: 'chevyEditor', classes: "chevy" , width: 35, align: 'center', editable: true, searchoptions: { sopt: ['eq', 'cn'] }, formatter: checkboxFormatter, formatoptions: { disabled: false }},
        { name: 'chevyTeam', index: 'chevyTeam', classes: 'chevy' , width: 35, align: 'center', editable: true, searchoptions: { sopt: ['eq', 'cn'] }, formatter: checkboxFormatter, formatoptions: { disabled: false }},
        { name: 'adminInd', index: 'adminInd', classes: 'admin', width: 35, align: 'center', editable: true, searchoptions: { sopt: ['eq', 'cn'] }, formatter: checkboxFormatter, formatoptions: { disabled: false } },
        { name: 'delete', index: 'delete', width: 8, sortable: false, search: false, formatter: deleteRow }
    ],
    emptyrecords: 'No records',
    pager: "#pager",
    rowNum: 1000,
    rowList: [],
    pgbuttons: false,
    pgtext: null,
    recordtext: 'Total Records {2}',
    sortname: 'userName', 
    sortorder: 'asc',
    viewrecords: true,
    caption: '',
    gridComplete: function () {
    },
    jsonReader:
    {
        root: "rows",
        page: "page",
        total: "total",
        records: "records",
        repeatitems: false,
        Id: "0"
    },
    width: 1500,
    height: 400,
    _search: true
});

Is there a different method I can try to change the colors of the column headers?

Answer №1

Instead of utilizing classes in the colModel, it is recommended to use labelClasses.

Answer №2

According to scrhartley, the functionality can be achieved using labelClasses in this manner:

$('#list').jqGrid({
    url: "/User/GetGridData",
    mtype: "GET",
    datatype: "json",
    colNames: ['', 'ID', 'Name', 'Email', 'ford Browser', 'ford Team', 'ford Director', 'chevy Browser', 'chevy Editor','chevy Team','Tool Admin',''],
    colModel: [
        { name: 'edit', index: 'edit', width: 5, sortable: false, search: false, formatter: editRow },
        { name: 'id', index: 'id', width: 1, hidden: true, editable: false, key: true },
        { name: 'userName', index: 'userName', width: 75, align: 'left', editable: true, searchoptions: { sopt: ['eq', 'cn'] } },
        { name: 'userEmail', index: 'userEmail', width: 100, align: 'left', editable: true, search: false  },
        { name: 'fordBrowser', index: 'fordBrowser', labelClasses: 'ford', width: 35, align: 'center', editable: true, searchoptions: { sopt: ['eq', 'cn'] }, formatter: checkboxFormatter, formatoptions: { disabled: false } },
        { name: 'fordTeam', index: 'fordTeam', labelClasses: 'ford',  width: 35, align: 'center', editable: true, searchoptions: { sopt: ['eq', 'cn'] }, formatter: checkboxFormatter, formatoptions: { disabled: false }},
        { name: 'fordDirector', index: 'fordDirector',labelClasses: 'ford', width: 35, align: 'center', editable: true, searchoptions: { sopt: ['eq', 'cn'] }, formatter: checkboxFormatter, formatoptions: { disabled: false }},
        { name: 'chevyBrowser', index: 'chevyBrowser', labelClasses: 'chevy' , width: 35, align: 'center', editable: true, searchoptions: { sopt: ['eq', 'cn'] }, formatter: checkboxFormatter, formatoptions: { disabled: false }},
        { name: 'chevyEditor', index: 'chevyEditor', labelClasses: "chevy" , width: 35, align: 'center', editable: true, searchoptions: { sopt: ['eq', 'cn'] }, formatter: checkboxFormatter, formatoptions: { disabled: false }},
        { name: 'chevyTeam', index: 'chevyTeam', labelClasses: 'chevy' , width: 35, align: 'center', editable: true, searchoptions: { sopt: ['eq', 'cn'] }, formatter: checkboxFormatter, formatoptions: { disabled: false }},
        { name: 'adminInd', index: 'adminInd', labelClasses: 'admin', width: 35, align: 'center', editable: true, searchoptions: { sopt: ['eq', 'cn'] }, formatter: checkboxFormatter, formatoptions: { disabled: false } },
        { name: 'delete', index: 'delete', width: 8, sortable: false, search: false, formatter: deleteRow }
    ],
    emptyrecords: 'No records',
    pager: "#pager",
    rowNum: 1000,
    rowList: [],
    pgbuttons: false,
    pgtext: null,
    recordtext: 'Total Records {2}',
    sortname: 'userName', 
    sortorder: 'asc',
    viewrecords: true,
    caption: '',
    gridComplete: function () {
    },
    jsonReader:
    {
        root: "rows",
        page: "page",
        total: "total",
        records: "records",
        repeatitems: false,
        Id: "0"
    },
    width: 1500,
    height: 400,
    _search: true});

An interactive demonstration is available here: jsfiddle

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips on eliminating excess white space or margins beneath a flexible video player

My issue is with a video and some content underneath. When I reduce the height of the video on mobile, there is too much white space below it. @media only screen and (max-width: 600px) { video { height: 80%; } Instead of adding margin-bottom ...

"Placing the save button on top of a div - a step

I am trying to position a div with an ID below a save button in my HTML code. The current setup looks like this: <button id="item_new" data-action="create" class="floating-button mdl-button mdl-js-button mdl-button--fab mdl-js-ripple-effect mdl-button- ...

variations in menu functionality on firefox

Could you please take a look at the links below? It appears that there may be an issue with FireFox. The green top menu seems to be displaying incorrectly. In Chrome/IE, it appears in one line, but in FF, the last two links are on the second line despite s ...

Select2 Bootstrap - Preselecting Options

I am currently utilizing Bootstrap Multiselect but I am encountering some difficulties setting the default value for the multiselect as per the documentation provided. Inside a function, I have tried the following: $("#selector").multiselect("select", ["V ...

How can I utilize an external file in Node js to output as a response?

I came across a similar inquiry, but I am interested in exploring manual methods. My goal is to achieve this without relying on express or any other external library. var http = require('http'); var server = http.createServer(function(req, res) ...

Adjust the color of radio button text with Jquery

Here is a sample of radio buttons: <input type='radio' name='ans' value='0'> Apple <input type='radio' name='ans' value='1'> Banana <input type='radio' name='ans&apo ...

Implementing a closing feature on an accordion-style display

I'm struggling with a jQuery problem that revolves around a horizontal timeline displaying events for a company. Each event is set up in an accordion effect, which is functioning correctly. However, I'm trying to add a close button to each panel ...

jQuery: Choose only one individual div to stay selected

Instructions: Directly underneath the BODY tag, there is a DIV element with the ID of "keepme" that must be retained. All other elements should be removed using the remove() method. Can you accomplish this task using jQuery? Specifically, preserving the s ...

Cannot get Vue.js component to display on Laravel 5.3 blade template

Currently, I am working with Laravel 5.3 and Vue version 1.0.26. However, I am facing an issue where the components are not loading into blade pages and appear empty. I have tried using the example component provided in Laravel. If anyone has a solution t ...

How to place a div within another div without using absolute positioning

I've been searching for a solution to this issue, but nothing seems to be working. I want the inner div to be positioned at the bottom of the outer div, with a 5px margin separating them. However, using absolute positioning disrupts the width and cent ...

"Adding an image to a select option using JavaScript: A step-by-step guide

Hey there, I'm looking for some assistance with appending an image src into a select option using JavaScript. Below is the code snippet: $.ajax({ type: "POST", url: "http://10.102.220.119:8001/api/1/device/devices", dataType: " ...

Managing element IDs with colons in jQuery

We are encountering difficulty accessing the div element with ID "test: abc" using jQuery in our JS code. <div id="test:abc"> $('#test:abc') Without the colon, everything works perfectly fine. Unfortunately, we do not have control over t ...

Executing the last item in a for loop multiple times can lead to unexpected outcomes in JavaScript

I am currently in the process of developing a JavaScript/jQuery version of a dice game that my friends and I enjoy playing. The latest iteration is designed for 3 players: http://codepen.io/jwnardini/pen/jmygqd My goal is to allow users to select the num ...

Utilizing jQuery to incorporate two datepickers for two separate fields (field 1 and field 2 with the second date being one day ahead), similar

How are you feeling? I am currently working with two datepickers, each associated with its own field. My goal is for the user to automatically select (From) and have the second field (TO) display the following day, similar to how it works on booking.com. ...

Attempting to utilize jQuery for altering the background URL leads to the unexpected removal of the -webkit-background-clip:text; effect

Can the -webkit-background-clip:text; effect be preserved when using jQuery to switch the background url? I am experiencing issues where changing the URL removes the text clipping effect. jQuery(function($) { var whatToSwitch = $('.homepage_ove ...

The background image is trapping my text and preventing it from moving forward

As a beginner developer embarking on my first web page project, I've encountered a challenge. The text I inserted into a flexbox refuses to align beneath the image. .title { text-align: center; width: 500px; margin-left: auto; margin-right: a ...

Ways to modify div content depending on the size of the screen

When the screen size becomes small, my goal is to modify the content within the row divs of the indices_container. Currently, all screen sizes display the index name, price, 1-day change, and year-to-date (YTD) change for each row. I only want to show the ...

Looking for and changing the background of a div element using jQuery's .find

Suppose I have a pair of div elements. How can I utilize the .find method to access the background image of div1, then transfer that background image to div2 while substituting ".jpg" with "_highlighted.jpg"? var div2bg = $('.div1').find(' ...

Maintain the center 1024px width while expanding the side columns to fit the entire page?

Is there a way to make the side divs extend to cover the entire page width? http://jsfiddle.net/p94vxnp2/1/ <style> #page_body_table { display: table; width: 100%; vertical-align: ...

No internet connection detected - please check your connection and try again

In the scenario where the internet connection is not available, when the user clicks a button, an error message should be displayed using a dialog box. I attempted to use navigator.online in my Android mobile webview but it did not work. How can I show t ...