当复选框为真时突出显示行 [英] Highlight row when the checkbox is true

查看:25
本文介绍了当复选框为真时突出显示行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我吗,我有一个 jqgrid,如果复选框为真,我想突出显示该行,谢谢!!

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

function loadjqGrid(jsonGridData){变量 xaxis=1300var yaxis = $(document).height();yaxis = yaxis-500;getGrids();$("#maingrid").jqGrid({url:'models/mod.quoservicetypedetails.php?ACTION=view',mtype: 'POST',数据类型:'xml',colNames:getColumnNames(jsonGridData),颜色模型:[{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"}},//如果GroupHeader为true,则行背景为黄色{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"}},],观看记录:真实,行数:20,排序名称:'id',观看记录:真实,排序顺序:降序",高度:yaxis,寻呼机:'#gridpager',记录文本:查看 {0} - {1} 个,共 {2} 个",emptyrecords: "没有要查看的记录",loadtext: "正在加载...",pgtext : "第 {0} 页,共 {1}",高度:yaxis,宽度: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: [{名称:'TypeID',索引:'TypeID',宽度:350,隐藏:true,edittype:选择",编辑选项:{值:getTypeID()},编辑规则:{edithidden:true}},{名称:'订单1',索引:'订单1',模板:myTextareaTemplate},{名称:'Order2',索引:'Order2',模板:myTextareaTemplate},{名称:'Order3',索引:'Order3',模板:myTextareaTemplate},{名称:'描述',索引:'描述',宽度:140,模板:myTextareaTemplate},{名称:'注释',索引:'注释',宽度:120,模板:myTextareaTemplate},{名称:'测量',索引:'测量',模板: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},

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆