复选框为真时突出显示行

Highlight row when the checkbox is true(复选框为真时突出显示行)
本文介绍了复选框为真时突出显示行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能帮帮我,我有一个 jqgrid,如果复选框为真,我想突出显示该行,谢谢!!

这就是我想在这个项目中做的......

函数 loadjqGrid(jsonGridData){变量 xaxis=1300var yaxis = $(document).height();yaxis = yaxis-500;获取网格();$("#maingrid").jqGrid({url:'models/mod.quoservicetypedetails.php?ACTION=view',mtype: 'POST',数据类型:'xml',colNames:getColumnNames(jsonGridData),col型号:[{name:'TypeID', index:'TypeID', width:350,hidden:true, align:'center',sortable:false,editable:true,编辑类型:选择",编辑选项:{值:getTypeID()},编辑规则:{编辑隐藏:真}},{name:'Order1', index:'Order1', width:80, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},{name:'Order2', index:'Order2', width:80, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},{name:'Order3', index:'Order3', width:80, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},{name:'Description', index:'Description', width:140, align:'center',sortable:false,editable:true,编辑类型:文本区域",编辑选项:{大小:30",最大长度:30"}},{name:'Notes', index:'Notes', width:120, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},{name:'Measure', index:'Measure', width:80, align:'center',sortable:false,editable:true, edittype:"textarea", editoptions:{size:"30",maxlength:"30"}},{name:'UnitPrice', index:'UnitPrice', width:100, align:'center',sortable:false,editable:false,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},{name:'Remarks', index:'Remarks', width:140, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},{name:'UnitCost', index:'UnitCost', width:100, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},{name:'Service', index:'Service', width:120, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},//如果GroupHeader为true,则行背景为黄色{name:'GroupHeader', index:'GroupHeader', width:100, align:'center',sortable:false,editable:true,formatter:'checkbox', edittype:'checkbox', type:'select', editoptions:{值:"1:0"}},{name:'IsGroup', index:'IsGroup', width:80, align:'center',sortable:false,editable:true,formatter:'checkbox', edittype:'checkbox', type:'select', editoptions:{值:"1:0"}},],观看记录:真实,行号:20,排序名称:'id',观看记录:真实,排序顺序:desc",高度:y轴,寻呼机:'#gridpager',recordtext: "查看 {0} - {1} of {2}",emptyrecords: "没有要查看的记录",loadtext: "加载中...",pgtext : "第 {0} 页,共 {1} 页",高度:y轴,宽度:x轴,收缩适应:假,多选:真,editurl:'models/mod.quoservicetypedetails.php?ACTION=edit'});}

我怎么能这样做?有人可以帮我吗?

解决方案

我在.该功能将使您的代码更短、更易读且易于维护.您需要做的是:

  • 您可以在 cmTemplete 的列定义中包含常用或最常用的设置.在你的情况下,它可能是

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

  • 然后您可以定义一些变量来描述您在某些列中经常使用的常见属性.例如:

var myCheckboxTemplate = {formatter: 'checkbox', edittype: 'checkbox', type: 'select',编辑选项:{值:1:0"}},myTextareaTemplate = {edittype:textarea",编辑选项:{大小:30",最大长度:30"}};

  • 之后,您可以在 colModel 中使用 myCheckboxTemplatemyTextareaTemplate ,这将在您的情况下减少到以下情况

colModel: [{name:'TypeID',索引:'TypeID',宽度:350,隐藏:true,edittype:选择",编辑选项:{值:getTypeID()},编辑规则:{编辑隐藏:真}},{名称:'Order1',索引:'Order1',模板:myTextareaTemplate},{名称:'Order2',索引:'Order2',模板:myTextareaTemplate},{名称:'Order3',索引:'Order3',模板:myTextareaTemplate},{名称:'描述',索引:'描述',宽度:140,模板:myTextareaTemplate},{名称:'Notes',索引:'Notes',宽度:120,模板:myTextareaTemplate},{名称:'Measure',索引:'Measure',模板:myTextareaTemplate},{名称:'UnitPrice',索引:'UnitPrice',宽度:100,可false,模板:myTextareaTemplate},{名称:'备注',索引:'备注',宽度:140,模板:myTextareaTemplate},{名称:'UnitCost',索引:'UnitCost',宽度:100,模板:myTextareaTemplate},{名称:'服务',索引:'服务',宽度:120,模板:myTextareaTemplate},//如果GroupHeader为true,则行背景为黄色{名称:'GroupHeader',索引:'GroupHeader',宽度:100,模板:myCheckboxTemplate},{名称:'IsGroup',索引:'IsGroup',模板:myCheckboxTemplate}],cmTemplate: {align: 'center', sortable: false, editable: true, width: 80},

Can Some one help me, I have a jqgrid and I want to highlight the row if the checkbox is true, thanks!!

this is what i want to make in this project...

function loadjqGrid(jsonGridData){
    var xaxis=1300
    var yaxis = $(document).height();
    yaxis = yaxis-500;
    getGrids();     
    $("#maingrid").jqGrid({
        url:'models/mod.quoservicetypedetails.php?ACTION=view',
        mtype: 'POST',
        datatype: 'xml',
        colNames:getColumnNames(jsonGridData),
        colModel :[ 
            {name:'TypeID', index:'TypeID', width:350,hidden:true, align:'center',sortable:false,editable:true,
            edittype:"select",editoptions:{value:getTypeID()},editrules: { edithidden: true}},  
            {name:'Order1', index:'Order1', width:80, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},                  
            {name:'Order2', index:'Order2', width:80, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}}, 
            {name:'Order3', index:'Order3', width:80, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},                      
            {name:'Description', index:'Description', width:140, align:'center',sortable:false,editable:true,
            edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},                    
            {name:'Notes', index:'Notes', width:120, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}}, 
            {name:'Measure', index:'Measure', width:80, align:'center',sortable:false,editable:true, edittype:"textarea", editoptions:{size:"30",maxlength:"30"}},                  
            {name:'UnitPrice', index:'UnitPrice', width:100, align:'center',sortable:false,editable:false,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},  
            {name:'Remarks', index:'Remarks', width:140, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}}, 
            {name:'UnitCost', index:'UnitCost', width:100, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},     
            {name:'Service', index:'Service', width:120, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}}, 
            //If the GroupHeader is true the row background is yellow
            {name:'GroupHeader', index:'GroupHeader', width:100, align:'center',sortable:false,editable:true,formatter:'checkbox', edittype:'checkbox', type:'select', editoptions:{value:"1:0"}}, 
            {name:'IsGroup', index:'IsGroup', width:80, align:'center',sortable:false,editable:true,formatter:'checkbox', edittype:'checkbox', type:'select', editoptions:{value:"1:0"}}, 
        ],
        viewrecords: true,  
        rowNum:20,
        sortname: 'id', 
        viewrecords: true, 
        sortorder: "desc",
        height: yaxis,
        pager : '#gridpager',
        recordtext: "View {0} - {1} of {2}",
        emptyrecords: "No records to view",
        loadtext: "Loading...",
        pgtext : "Page {0} of {1}",         
        height: yaxis,
        width: xaxis,
        shrinkToFit: false,
        multiselect: true,
        editurl:'models/mod.quoservicetypedetails.php?ACTION=edit'
    }); 
}

How could I do this? Can someone help me?

解决方案

I described in the answer one good way how you can implement the highlighting.

Version 4.3.2 of jqGrid has new feature - rowattr callback (see my original suggestion), which was introduced especially for cases like yours. It allows you to highlight some rows of grid during filling of the grid. To have the best performance advantage you should use gridview: true additionally. By the way I recommend you to use gridview: true in all jqGrids.

The usage of rowattr callback is very easy:

gridview: true,
rowattr: function (rd) {
    if (rd.GroupHeader === "1") { // verify that the testing is correct in your case
        return {"class": "myAltRowClass"};
    }
}

The CSS class myAltRowClass should define background color of highlighted rows.

The corresponding demo you can find here:

Because in your demo you need just highlight and not select the rows I didn't used multiselect: true in my demo. In case of multiselect: true it works exactly in the same way.

At the end of my answer I would like to recommend you to use column templates. The feature will make your code shorter, more readable and easy to maintain. What you need to do is the following:

  • you can include common or the most frequently used settings from column definitions in cmTemplete. In your case it could be

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

  • then you can define some variables which describe common properties which you use frequently in some columns. For example:

var myCheckboxTemplate = {formatter: 'checkbox', edittype: 'checkbox', type: 'select',
        editoptions: {value: "1:0"}},
    myTextareaTemplate = {edittype: "textarea",
        editoptions: {size: "30", maxlength: "30"}};

  • after that you can use myCheckboxTemplate and myTextareaTemplate inside of colModel which will reduced in your case to the following

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},

这篇关于复选框为真时突出显示行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)