【问题标题】:Disable or enable action in jqgrid在 jqgrid 中禁用或启用操作
【发布时间】:2013-06-09 10:47:53
【问题描述】:

我在应用程序中使用 jqgrid 和自定义操作格式化程序。我在loadComplete 时创建动作。 我想根据 Col1 的值禁用/启用此操作,例如,如果 col1 的值为 true 则可见的操作设置为 true.... 怎么做?

 grid.jqGrid({
    url: 'jqGridHandler.ashx',
    datatype: 'json',
    colNames: ['Action','Col1','col2'],
    colModel: [
        {
            name: 'act',
            width: ($.browser.webkit ? 25 : 25),
            align: 'center',
            sortable: false,
            formatter: 'actions',
            formatoptions: {
                keys: true,
                delbutton: false,
                editbutton: false
            }
        },
        { name: 'Col1', width: 100, sortable: true, hidden: true },
        { name: 'col2', width: 100, sortable: true, hidden: true }
    ],
    rowNum: 20,
    rowList: [5, 10, 20],
    recordpos: "left",
    toppager: true,
    viewrecords: true,
    sortorder: "desc",
    scrollOffset: 1,
    jsonReader:
    {
        repeatitems: false,
    },
    gridview: true,
    loadComplete: function () {
        var iCol = getColumnIndexByName(grid, 'act');
        $(this).find(">tbody>tr.jqgrow>td:nth-child(" + (iCol + 1) + ")")
            .each(function () {
                $("<div>", {
                    title: "MyAction",
                    mouseover: function () {
                        $(this).addClass('ui-state-hover');
                    },
                    mouseout: function () {
                        $(this).removeClass('ui-state-hover');
                    },
                    click: function (e) {
                        alert("'Custom' button is clicked in the rowis=" +
                            $(e.target).closest("tr.jqgrow").attr("id") + " !");
                    }
                }
                ).css({ "margin-right": "5px", "float": "left", "cursor": "pointer" })
                    .addClass("ui-pg-div ui-inline-custom")
                    .append('<span class="ui-icon icon-archive"></span>')
                    .prependTo($(this).children("div"));
            });
    },

【问题讨论】:

    标签: jquery asp.net jqgrid webforms


    【解决方案1】:

    我会尝试过滤集合并只做正确的单元格

    var iCol = getColumnIndexByName(grid, 'act');
    var iCol1 = getColumnIndexByName(grid, 'Col1'); 
    $(this).find(">tbody>tr.jqgrow>td:nth-child(" + (iCol + 1) + ")")
    //  .each(function () {
    
      .filter(function (index) {
          true==$(this).find(">tbody>tr.jqgrow>td:nth-child(" + (iCol1 + 1) + ")").val();
    }) {
    

    【讨论】:

    • 我在哪里使用过滤器?找到后?
    • 它不起作用可能是我错了。 var data = $(this).find(">tbody>tr.jqgrow>td:nth-child(" + (iCol + 1) + ")").filter(function(index) { $(this).find (">tbody>tr.jqgrow>td:nth-child(" + (iCol1 + 1) + ")").val() == 'True';});
    • 我用心写代码,可惜毁了。该函数必须返回语句: return true==$(this).find(">tbody>tr.jqgrow>td:nth-child(" + (iCol1 + 1) + ")").val();
    • 我用心写代码,可惜毁了。该函数必须返回语句: return true==$(this).find(">tbody>tr.jqgrow>td:nth-child(" + (iCol1 + 1) + ")").val();此外,您应该检查返回 $(this).find.(...).val() 命令的内容,在警报中或在控制台上,是否有利于比较。如果您有任何疑问,或者您可以将其设为 jsfiddle,请告诉我!
    猜你喜欢
    • 1970-01-01
    • 2013-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-19
    • 2014-01-13
    • 1970-01-01
    相关资源
    最近更新 更多