Home > Web Front-end > JS Tutorial > How to Highlight Rows in a JqGrid Based on Checkbox Status?

How to Highlight Rows in a JqGrid Based on Checkbox Status?

DDD
Release: 2024-11-07 10:49:02
Original
883 people have browsed it

How to Highlight Rows in a JqGrid Based on Checkbox Status?

Highlight Rows When Checkbox is True

In your jqGrid project, you aim to highlight rows based on the status of a checkbox.

Rowattr Callback

Version 4.3.2 of jqGrid introduces the rowattr callback, which allows you to add custom attributes to rows during the grid fill process. This is a suitable approach for row highlighting.

rowattr: function (rd) {
    if (rd.GroupHeader === "1") { // Verify this logic based on your data structure
        return {"class": "myAltRowClass"};
    }
}
Copy after login

CSS Class for Highlighting

Define a CSS class myAltRowClass that sets the background color for highlighted rows.

Multiselect and gridview

For row highlighting without row selection, omit multiselect: true. To enhance performance, enable gridview: true.

Usage of Column Templates

To streamline your code, you can utilize column templates:

cmTemplate

cmTemplate: {align: 'center', sortable: false, editable: true, width: 80}
Copy after login

Custom Templates

Create custom templates for commonly used properties:

var myCheckboxTemplate = {
    formatter: 'checkbox',
    edittype: 'checkbox',
    type: 'select',
    editoptions: {value: "1:0"}
};

var myTextareaTemplate = {
    edittype: "textarea",
    editoptions: {size: "30", maxlength: "30"}
};
Copy after login

Optimized colModel

colModel: [
    {name: 'TypeID', index: 'TypeID', width: 350, hidden: true, edittype: "select",
        editoptions: {value: getTypeID()}, editrules: { edithidden: true}},
    {name: 'Order1', index: 'Order1', template: myTextareaTemplate},
    {name: 'Order2', index: 'Order2', template: myTextareaTemplate},
    {name: 'Order3', index: 'Order3', template: myTextareaTemplate},
    {name: 'Description', index: 'Description', width: 140, template: myTextareaTemplate},
    {name: 'Notes', index: 'Notes', width: 120, template: myTextareaTemplate},
    {name: 'Measure', index: 'Measure', template: myTextareaTemplate},
    {name: 'UnitPrice', index: 'UnitPrice', width: 100, editable: false, template: myTextareaTemplate},
    {name: 'Remarks', index: 'Remarks', width: 140, template: myTextareaTemplate},
    {name: 'UnitCost', index: 'UnitCost', width: 100, template: myTextareaTemplate},
    {name: 'Service', index: 'Service', width: 120, template: myTextareaTemplate},
    //If the GroupHeader is true the row background is yellow
    {name: 'GroupHeader', index: 'GroupHeader', width: 100, template: myCheckboxTemplate},
    {name: 'IsGroup', index: 'IsGroup', template: myCheckboxTemplate}
],
cmTemplate: {align: 'center', sortable: false, editable: true, width: 80}
Copy after login

The above is the detailed content of How to Highlight Rows in a JqGrid Based on Checkbox Status?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template