删除/添加类到jqgrid行

时间:2013-07-28 12:41:35

标签: jquery jqgrid

我在rowattr中的条件基础上添加了类的行。我在网格中添加操作按钮,当点击动作时必须删除当前行的'class1'并添加'class2'。 怎么做?

$("#gridParaf").jqGrid(
{
    url: "GetLetterInformationHandler.ashx?CurrentUser=" + 1457,
        datatype: 'json',
        colNames: ['action', 'IAnsDateTime', 'IAnsState'],
        colModel: [
            { name: 'IAnsDateTime', width: 50, sortable: false, hidden: false, template: CenterTemplate },
            { name: 'IAnsState', width: 20, sortable: false, hidden: false, template: CenterTemplate },
            { name: 'SysCode', width: 20, sortable: false, hidden: true,key:true },
        ],
        rowNum: 10,
        loadonce: true,
        rowList: [5, 10, 20],
        recordpos: "left",
        rowattr: function (rd) {
            var viewDate = grid.getGridParam("userData")[rd["SysCode"]]["IAnsDateTime"];
            return { "class": (viewDate == '') ? "class1" : "class2" };
        },
        loadComplete: function() {
            $("<div>", {
                    title: "I like it",
                    mouseover: function() {
                        $(this).addClass('ui-state-hover');
                    },
                    mouseout: function() {
                        $(this).removeClass('ui-state-hover');
                    },
                    click: function(e) {
                        window.rowData = grid.getGridParam("userData")[$(e.target).closest("tr.jqgrow").attr("id")];
                    }
                }
            ).css({ "margin-right": "10px", "float": "left", cursor: "pointer" })
                .append('<span class="ui-icon icon-Confirm "></span>')
                .prependTo($(this).children("div"));
        },

1 个答案:

答案 0 :(得分:0)

我通过this answer

解决了我的问题
var tr = window.grid[0].rows.namedItem(window.selectedRow);
$(tr).removeClass("class1");
$(tr).addClass("class2");