javascript 选择jqgrid中所有复选框的功能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19587963/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 16:04:22  来源:igfitidea点击:

Function to select all checkbox in jqgrid

javascriptjquerycheckboxjqgrid

提问by Developer123

I have a jqgrid and the first column I have a checkbox (checkAll others checkbox). I don't know how i do it. How I do a function to select all others checkbox in my jqgrid?

我有一个 jqgrid,第一列有一个复选框(选中所有其他复选框)。我不知道我是怎么做的。我如何做一个功能来选择我的 jqgrid 中的所有其他复选框?

$.getJSON("/Page/Table", function (data) {
        var data = data;
        $('#table').jqGrid({
            datatype: 'local',
            data: dados,
            colNames: ['<input type="checkbox" id="checkAll" onclick="checkBox(event)" />', 'UserName', 'Code', 'Email'],
            colModel: [
                        {
                            name: 'checkbox',
                            width: 50,
                            resizable: true,
                            editable: true,
                            align: 'center',
                            edittype: 'checkbox',
                            formatter: "checkbox",
                            formatoptions: { disabled: false },
                            classes: 'check',
                            editrules: { required: false }, editoptions: { size: 39, value: "True:False" }
                        },
                        { name: 'userName', width: 200, index: 'userName', align: 'left' },
                        { name: 'code', width: 80, index: 'code' },
                        { name: 'Email', width: 150, align: 'left', index: 'Email'}],
            viewrecords: true,
            imgpath: 'jqGrid-3.4.3/themes/coffee/images',
            caption: '',
            rownumbers: true,
            height: 'auto',
            width: 1860,
            scrollOffset: 0
        });

回答by Oleg

Probably it would be better to use multiselect: trueoption which will create the column with checkboxs in the grid? All functionality which you try to implement seems be directly in the grid.

使用multiselect: true选项可能会更好,该选项将在网格中创建带有复选框的列?您尝试实现的所有功能似乎都直接在网格中。

回答by Sridhar R

by using common class for checkboxes using jquery we can do

通过使用 jquery 对复选框使用通用类,我们可以做到

$('.check').attr('checked', true);

回答by pala?н

Modify the first colNamesas:

将第一个修改colNames为:

colNames: ['<input type="checkbox" id="checkAll" onclick="checkBox(this)" />',

and the JSfunction as this:

JS函数是这样的:

function checkBox(obj) {
    $('.check').prop('checked', obj.checked);
}