jqGrid checkbox events

允我心安 提交于 2020-01-15 05:11:12

问题


I have a jqGrid it has a checkbox in the rows. I need to be able to change the value depending of if it is being checked or unchecked. Using this in the $(document).ready block does not work. I have tried multiple solutions that I have found on the forum and nothing seems to work. Any suggestions?

 $('#glReportCodesGrid').children("input:checkbox").click(function () {
    var y = $(this).val();
    if (y == 'false') {
        $(this).val('true');
    }
    else { $(this).val('false'); }
});

回答1:


You need to use the following selector to find the checkboxes:

jQuery(".jqgrow td input", "#glReportCodesGrid").click(function () {

You would need to call the above from one of the grid events that is triggered after the grid is initialized.

Alternatively, you can use jQuery.delegate to dynamically bind the event handler when the elements are created:

jQuery(document).delegate(
    '#glReportCodesGrid .jqgrow td input', 
    'click', 
    function () { ... });

The question jqgrid-with-an-editable-checkbox-column has some related information that you may find helpful.



来源:https://stackoverflow.com/questions/8156122/jqgrid-checkbox-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!