Jqgrid flag change event

I have true / false values ​​in my database. I want to update them using a checkbox in jqgrid. When the value is set to true, it will remain true and should not be changed. Please take a look at my column model:

{ name : 'available', width : 12, resizable: true, editable: true, align: 'center', edittype:'checkbox', formatter: "checkbox", formatoptions: {disabled : false}, classes:'check', editrules:{required:false}, editoptions:{size:39,value:"True:False"} } 

I am trying to capture an event when the checkbox is checked, currently they are not all checked, so far I have tried:

 jq(".check input").each(function(){ jq(this).click(function(){ aler("works"); }); }); jq("input[type='checkbox']").change(function(){ alert("works"); }); jq(":checkbox").parent().click(function(evt) { if (evt.target.type !== 'checkbox') { var $checkbox = jq(":checkbox", this); $checkbox.attr('checked', !$checkbox.attr('checked')); $checkbox.change(); alert(""); } }); 

None of these works, I am stuck, do not know what else to try.

When checking the flag code with firebug it looks like this:

 <input type="checkbox" offval="no" value="false"> 
+6
source share
3 answers

Using custom formatting is one option. You can also use the unobtrusive onclick binding style

First determined

 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 in loadComplete you can use 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 .

+4
source

You can create your own formatter. In your grid

 formatter: cboxFormatter, 

Then we define a function,

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

You can use onclick to accomplish your task or function call.

+6
source

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); }); 
+1
source

Source: https://habr.com/ru/post/888779/


All Articles