在jqgrid中选中所有复选框的功能

Function to select all checkbox in jqgrid

本文关键字:复选框 功能 jqgrid      更新时间:2023-09-26

我有一个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
        });
也许最好

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

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

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

将第一个colNames修改为:

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

JS函数如下:

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