jqgrid checkbox change event

前端 未结 3 1002
被撕碎了的回忆
被撕碎了的回忆 2020-12-11 17:38

I have true/false values in my database. I want to update them with checkbox in jqgrid. Once the value is set to true, it will remain true and should not change. Please tak

相关标签:
3条回答
  • 2020-12-11 17:43

    The usage of the custom formatter is one of the possibilities. One can also use unobtrusive style of onclick binding

    First one defines

    var grid = $("#list"),
        getColumnIndexByName = function(columnName) {
            var cm = grid.jqGrid('getGridParam','colModel'),i=0,l=cm.length;
            for (; i<l; i++) {
                if (cm[i].name===columnName) {
                    return i; // return the index
                }
            }
            return -1;
        },
        disableIfChecked = function(elem){
            if ($(elem).is(':checked')) {
                $(elem).attr('disabled',true);
            }
        };
    

    Then one can use the in the loadComplete the code like

    loadComplete: function() {
        var i=getColumnIndexByName('closed');
        // nth-child need 1-based index so we use (i+1) below
        $("tbody > tr.jqgrow > td:nth-child("+(i+1)+") > input",
          this).click(function(e) {
            disableIfChecked(this);
        }).each(function(e) {
            disableIfChecked(this);
        });
    }
    

    See the corresponding demo here.

    0 讨论(0)
  • 2020-12-11 17:43

    You can create a custom formatter. In your grid,

    formatter: cboxFormatter,
    

    Then define the function,

    function cboxFormatter(cellvalue, options, rowObject)
    {
      return '<input type="checkbox"' + (cellvalue ? ' checked="checked"' : '') + 
          'onclick="alert(' + options.rowId + ')"/>';
    }
    

    You can use onclick to perform your task or call a function.

    0 讨论(0)
  • 2020-12-11 18:07

    This worked for me:

        // Listen for Click Events on the 'Process' check box column
        $(document).on("click", "td[aria-describedby='grdOrders_Process']", function (e) {
            var checked = $(e.target).is(":checked")
    
            var rowId = $(e.target).closest("tr").attr("id")
            rowData = jQuery("#grdOrders").getRowData(rowId);
    
            alert("Checked: " + checked)
            alert("OrderNo: " + rowData.OrderNo);
            alert("Name: " + rowData.Name);
        });
    
    0 讨论(0)
提交回复
热议问题