最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jqGrid checkbox events - Stack Overflow

programmeradmin0浏览0评论

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'); }
});

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'); }
});
Share Improve this question edited Nov 16, 2011 at 20:07 Justin Ethier 134k52 gold badges232 silver badges287 bronze badges asked Nov 16, 2011 at 17:40 Russell WaltersRussell Walters 863 silver badges11 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

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.

发布评论

评论列表(0)

  1. 暂无评论