【问题标题】:jqgrid rowattr not applying classjqgrid rowattr没有应用类
【发布时间】:2014-08-15 17:38:49
【问题描述】:

我想根据列的值将背景颜色应用于 jqGrid 行的行,但是基本的 rowattr 没有将类应用于行。

以下是代码(为简单起见,我删除了需要应用颜色的条件)

       jQuery("#employeeSalarysGrid").jqGrid({
            height: 250,
            url: 'http://localhost:50570/api/Test/Get',
            mtype: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: "json",
            serializeGridData: function (postData) {
                return JSON.stringify(postData);
            },
            jsonReader: {
                root: function (obj) { return obj; },
                page: function (obj) { return 1; },
                total: function (obj) { return 1; },
                records: function (obj) { return obj.length; },
                id: "0",
                cell: "",
                repeatitems: false
            },
            datatype: "json",

            colNames: ['Id', 'Bank Name', 'Bank Name', 'Employee name', 'Joining date', 'Salary amount', 'Comments'],
            colModel: [
                { name: 'Id', align: "center", hidden: true },
                { name: 'BankName', index: 'BankName', align: 'center', editable: false },
                {
                    name: 'BankId', index: 'BankId', align: "center", hidden: true, required: true,
                    viewable: true, editrules: { edithidden: true, required: true },
                    editable: true,
                    edittype: 'select',
                    editoptions: {
                        dataUrl: '/api/Test/GetBanks',
                        buildSelect: function (data) {
                            var response = jQuery.parseJSON(data);
                            var s = '<select>';
                            if (response && response.length) {
                                for (var i = 0, l = response.length; i < l; i++) {
                                    var bank = response[i];
                                    s += "<option value=" + bank.BankId + ">" + bank.Name + "</option>";
                                }
                            }
                            return s + "</select>";
                        }
                    }
                },
                { name: 'EmployeeName', align: "center", editable: true, editrules: { required: true } },
                { name: 'JoiningDate', align: "center", editable: true, editrules: { custom: true, custom_func: datecheck },
                    formatter: 'date', formatoptions: { srcformat: 'y-m-d', newformat: 'd-M-y' }, edittype: 'text', editable: true,
                    editoptions: { dataInit: function (el) { setTimeout(function () { $(el).datepicker({ dateFormat: 'd-M-y' }); }, 200); } }
                },
             //{ name: 'cdate', index: 'cdate', width: 80, align: 'right', formatter: 'date', srcformat: 'yyyy-mm-dd', newformat: 'm-d-Y', edittype: 'text', editable: true, editoptions: { dataInit: function (el) { setTimeout(function () { $(el).datepicker(); }, 200); } } },

                { name: 'SalaryAmount', align: "center", editable: true, editrules: { required: true } },
                { name: 'Comments ', align: "center", editable: true }
            ],
            gridview: true,
            autoencode: true,
            ignorecase: true,
            loadonce: true,
            sortname: "InstallmentDate",
            sortorder: "asc",
            viewrecords: true,
            rowNum: 10,
            rowList: [10, 15, 20],
            pager: '#employeeSalarysPager',
            caption: "Employee Salary list",
           rowattr: function (rd) {                    
                return { "class": "rowClass" };
                //alert("hi");


            }
        });

CSS 样式:

 <style type="text/css">      
        .rowClass { color: blue;  background-image: none;}
    </style>

注意:如果我取消注释 //alert 语句,它会显示 5 次警报消息。这意味着每行都会调用 rowattr,但是没有应用 css 类。

问候, 阿比拉什

【问题讨论】:

  • 您在测试中使用哪个网络浏览器和哪个版本?您使用哪个 jQuery UI 主题(以及哪个版本的 jQuery UI)?我无法在测试中重现该问题。
  • 浏览器:IE,版本:11 CSS:jquery ui 1.10.4 脚本:jquery-2.1.0 如果您需要更多详细信息,请告诉我。谢谢!

标签: css jqgrid


【解决方案1】:

rowattr 确实可以正常工作,但是如果您希望该类也将应用于选定的行,那么您应该将 CSS 规则更改为以下内容

.ui-widget-content .rowClass { color: blue;  background-image: none; }

the demo

【讨论】:

  • 我认为 rowattr 与 cellattr 一起在 colmodel 中会更有用。这样,您可以根据原始对象上的条件更改行属性,例如在 cellattr 中。使用当前的实现,您只能在构建行之后访问显示的值,这不是那么有用,并且迫使您使用 jquery 做一些相当混乱的事情来解析单元格内容。
  • @singe3: colModel 是定义列单元格属性的项数组 (&lt;td&gt; elemens)。 rowattr 定义行的属性(&lt;tr&gt; 元素)。因此,不能将rowattr 放置在一些或每个colModel 项目中。 cellattr 定义列单元格的属性 (&lt;td&gt; elemens)。因此它位于colModelrowattrcellattr 都将在构建网格主体的 HTML 片段期间应用。 rowattr 是有效的,因为它不更改行属性。它设置/指定属性。
猜你喜欢
  • 2016-07-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多