JQuery DataTable只选择最近复选框状态已更改的行

时间:2017-12-27 18:42:59

标签: jquery datatables

附上代码。我能够获得复选框的状态(真/假)。现在我的问题是......

问题:

如何仅在复选框状态已更改的情况下获取行?不是全部。

我的下面的函数Btn_SaveOrganizationsRights只改进了代码。任何优化。

功能抱歉.access-view个类没有附加到复选框。但想想附::)

$('#Btn_SaveOrganizationsRights').on('click', function (e) {
        e.preventDefault();

        grid = new Array();
        var roleId = 12;
        organizationsTable.rows().eq(0).each(function (index) {
            var row = organizationsTable.row(index);

            var orgId = row.data().orgId;
            var hasAccessView = row.$('.access-view', row).is(':checked');
            var hasCreateView = row.$('.access-create', row).is(':checked');
            var hasEditView = row.$('.access-edit', row).is(':checked');
            var hasDeleteView = row.$('.access-delete', row).is(':checked');
            var hasAuthView = row.$('.access-auth', row).is(':checked');
            var hasPublishView = row.$('.access-publish', row).is(':checked');

            grid[index] = roleId + "," + orgId + "," + hasAccessView + "," + hasCreateView + "," + hasEditView + "," + hasDeleteView + "," + hasAuthView + "," + hasPublishView;

        });

DATATABLE

var organizationsTable = $("#organizations").DataTable({
        "processing": true,
        "filter": true,
        "paging": false,
        "info": true,
        "searching": true,
        "orderMulti": false,
        "aaData": myjson,
        "columnDefs":
        [
            {
                "targets": [0],
                "visible": true,
                "searchable": false,
            },
            {
                "targets": [1],
                "visible": true,
                "searchable": false,
            },
            {
                'targets': 2,
                "orderable": false,
                'className': 'centert-align',
                render: function (data, type, row) {
                    return data;
                }
            },
            {
                'targets': 3,
                "orderable": false,
                'className': 'centert-align',
                render: function (data, type, row) {
                    if (type === 'display') {
                        return '<input type="checkbox" ' + ((data == 1) ? 'checked' : '') + ' id="input' + row.id + '" class="filter-ck" />';
                    }
                    return data;
                }
            },
            {
                'targets': 4,
                "orderable": false,
                'className': 'centert-align',
                render: function (data, type, row) {
                    if (type === 'display') {
                        return '<input type="checkbox" ' + ((data == 1) ? 'checked' : '') + ' id="input' + row.id + '" class="filter-ck" />';
                    }
                    return data;
                }
            },
            {
                'targets': 5,
                "orderable": false,
                'className': 'centert-align',
                render: function (data, type, row) {
                    if (type === 'display') {
                        return '<input type="checkbox" ' + ((data == 1) ? 'checked' : '') + ' id="input' + row.id + '" class="filter-ck" />';
                    }
                    return data;
                }
            },
            {
                'targets': 6,
                "orderable": false,
                'className': 'centert-align',
                render: function (data, type, row) {
                    if (type === 'display') {
                        return '<input type="checkbox" ' + ((data == 1) ? 'checked' : '') + ' id="input' + row.id + '" class="filter-ck" />';
                    }
                    return data;
                }
            },
            {
                'targets': 7,
                "orderable": false,
                'className': 'centert-align',
                render: function (data, type, row) {
                    if (type === 'display') {
                        return '<input type="checkbox" ' + ((data == 1) ? 'checked' : '') + ' id="input' + row.id + '" class="filter-ck" />';
                    }
                    return data;
                }
            },
            {
                'targets': 8,
                "orderable": false,
                'className': 'centert-align',
                render: function (data, type, row) {
                    if (type === 'display') {
                        return '<input type="checkbox" ' + ((data == 1) ? 'checked' : '') + ' id="input' + row.id + '" class="filter-ck" />';
                    }
                    return data;
                }
            }
        ],
        "columns": [
            { "data": "roleId" },
            { "data": "orgId" },
            { "data": "name" },
            { "data": "viewAccess" },
            { "data": "createAccess" },
            { "data": "editAccess" },
            { "data": "deleteAccess" },
            { "data": "authAccess" },
            { "data": "publishAccess" },
            {
                "orderable": false,
                data: null, render: function (data, type, row) {
                    return '<button type="submit" class="btn green linkorg_save cancel">SAVE</button>'
                }
            }
        ],
        'order': [1, 'asc']
    });

0 个答案:

没有答案