Home > Web Front-end > JS Tutorial > How to Highlight Rows in jqGrid Based on Checkbox Value?

How to Highlight Rows in jqGrid Based on Checkbox Value?

Susan Sarandon
Release: 2024-11-07 06:41:03
Original
576 people have browsed it

How to Highlight Rows in jqGrid Based on Checkbox Value?

Highlighting Rows Based on Checkbox Value

In jqGrid, you can highlight rows where a specific checkbox is true, giving you visual feedback when certain conditions are met. This can be achieved through callbacks and CSS styling.

Implementation:

  1. Rowattr Callback: Utilize the rowattr callback to set custom attributes to rows. In your case, you can define a CSS class for highlighted rows.
rowattr: function (rd) {
    if (rd.GroupHeader === "1") { // assuming your checkbox column is named "GroupHeader"
        return {"class": "myAltRowClass"};
    }
}
Copy after login
  1. CSS Styling: Define a CSS class to control the appearance of highlighted rows. For example, you could use the following:
.myAltRowClass {
    background-color: #ffff00;
}
Copy after login

Alternative Solution:

In addition to the rowattr callback, jqGrid version 4.3.2 offers a new feature called gridview, which enhances performance and provides a neater way to highlight rows.

gridview: true,
rowattr: function (rd) {
    if (rd.GroupHeader === "1") { // assuming your checkbox column is named "GroupHeader"
        return {"class": "myAltRowClass"};
    }
}
Copy after login

Column Templates:

To streamline your code, consider using column templates to define common properties for multiple columns. This simplifies your column definitions and makes them easier to maintain.

cmTemplate: {align: 'center', sortable: false, editable: true, width: 80},
...
colModel: [
    {name: 'TypeID', ...},
    {name: 'Order1', template: myTextareaTemplate},
    // ...
]
Copy after login

Example:

#maingrid").jqGrid({
    rowattr: function (rd) {
        if (rd.GroupHeader === "1") { // assuming your checkbox column is named "GroupHeader"
            return {"class": "myAltRowClass"};
        }
    },
    cmTemplate: {align: 'center', sortable: false, editable: true, width: 80},
    colModel: [
        {name: 'TypeID', ...},
        {name: 'Order1', template: myTextareaTemplate},
        // ...
    ]
});
Copy after login

The above is the detailed content of How to Highlight Rows in jqGrid Based on Checkbox Value?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template