How to reset Selection for multiple pages

邮差的信 提交于 2019-12-25 03:13:39

问题


Currently I'm using free-jqgrid 4.15.4 where I have a requirement to select multiple rows across pages, send email to participants and then reset Selection in one go. For that I'm using multiselect: true,multiPageSelection: true, $('#grid').jqGrid('resetSelection'); in ajax callback of function.

But I think the resetSelectioncode is not working for multiple pages, rather it works only for current page (removes all the checked boxes).

Here is the fiddle that shows implementation of resetSelection in the grid.

Here is the code:

$(function () {
"use strict";
var mydata = [
    { Id: "10",  FirstName: "test",     LastName: "TNT", Gender: "Male" },
    { Id: "11",  FirstName: "test2",    LastName: "ADXC", Gender: "Male" },
    { Id: "12",  FirstName: "test3",    LastName: "SDR", Gender: "Female" },
    { Id: "13",  FirstName: "test4",    LastName: "234", Gender: "Male" },
    { Id: "14",  FirstName: "test5",    LastName: "DAS", Gender: "Male" },
];
$("#list").jqGrid({
    data: mydata,
    colNames: ['',/*'Id',*/ 'First Name', 'Last Name', 'Gender'],
    colModel: [
        {
            name: "act", template: "actions",
            formatoptions: {
                delbutton: false
            }
        },
        /*{
            label: "Id",
            name: 'Id',
            hidden: true,
            search: false,
        },*/
        {
            //label: "FirstName",
            name: 'FirstName',
            searchoptions: {
                searchOperators: true,
                sopt: ['eq', 'ne', 'lt', 'le','ni', 'ew', 'en', 'cn', 'nc'],
            }, search: true,
        },
        {
            //label: "LastName",
            name: 'LastName',
            searchoptions: {
                searchOperators: true,
                sopt: ['eq', 'ne', 'lt', 'ni', 'ew', 'en', 'cn', 'nc'],
            }, search: true,
        },
        {
            //label: "Gender",
            name: 'Gender',
            //search: true, 
            edittype: "select", editable: true,
            editoptions: {
                value: "Male:Male;Female:Female" //"Male:Male;Female:Female;" ,                                                                 
            },
            stype: "select",
            editrules: {
                custom: true,
                custom_func: function (value, colName, iCol)                                                    {
                    alert("The value to validate: " +value);
                    return [true];
                }
            }
        },
    ],
    /*onSelectRow: function (id) {
        if (id && id !== lastsel) {
            jQuery('#list').restoreRow(lastsel);
            jQuery('#list').editRow(id, true);
            lastsel = id;
        }
    },*/
    afterSaveCell: function (rowid, cmName, value, iRow, iCol) {
        var $self = $(this);

        if (cmName === "Gender") {
            $self.jqGrid("getGridParam", "selarrrow").forEach(function (id) {
                var item = $self.jqGrid("getLocalRow", id);
                if (id !== rowid && item.Gender !== value) {
                    $self.jqGrid("setCell", id, iCol, value, false, false, true);
                }
            });
        }
    },
    loadComplete: function (id) {
        var $self = $(this);
        if ($self.getGridParam('records') === 0) {

            //$('#grid tbody').html("<div style='padding:6px;background:#D8D8D8;'>No records found</div>");
        /*} else {
            var lastsel = 0;
            if (id && id !== lastsel) {
                $self.restoreRow(lastsel);
                $self.editRow(id, true);
                lastsel = id;
            }*/
        }
    },
    pager: true, //jQuery('#pager'),
    //loadonce: true,
    viewrecords: true,
    //gridview: true,
    //width: 'auto',
    height: 450, // '450px',
    iconSet: "fontAwesome",
    multiselect: true,
multiPageSelection: true,
    cellEdit:true,
rowNum: 2,
    emptyrecords: "No records to display",
    jsonReader: {
        repeatitems: false,
        id: "Id" //Id: "Id"
    },
    localReader: { id: "Id" },
    prmNames: { id: "Id" }
});
$('#list').jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: "cn", multipleSearch: true, searchOperators: true, search: true, loadFilterDefaults: true });
$('#list').jqGrid('navGrid', "#pager", {
    search: true, // show search button on the toolbar
    add: true,
    edit: false,
    del: false,
    refresh: true,
    reloadGridOptions: { fromServer: true }
}); 
$("#list").jqGrid("navButtonAdd", {
    caption: "",
    buttonicon: "fa fa-eraser",
    title: "Clear Selection",
    onClickButton: function (e) {
        var myGrid = $('#list');
        myGrid.jqGrid('resetSelection');          
    }
});
});

The only change I see is that I've used data: json in actual jqgrid.

来源:https://stackoverflow.com/questions/54314494/how-to-reset-selection-for-multiple-pages

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