Make jqGrid multiselect selection persist following pagination, toolbar search, or filter

家住魔仙堡 提交于 2019-12-04 08:11:15

here is the script. onSelectAll and onSelectRow allow to save the state which is restored in gridComplete

$(function () {

            var selectedRows = {};
            var agentsGrid = $('#agentsTbl');
            agentsGrid.jqGrid({
                height: 400,
                datatype: 'local',
                multiselect: true,
                ignoreCase: true,
                colNames: [
                    'isn', 'Agent', 'Type', 'Country', 'Plan', 'Date To'],
                colModel: [
                    { name: 'isn', index: 'isn', hidden: true, key: true, align: 'center' },
                    { name: 'agentName', index: 'agentName', align: 'center', search: true, stype: 'text', searchoptions: { sopt: ['cn'] } },
                    { name: 'agentType', index: 'agentType', hidden: true },
                    { name: 'country', index: 'country', align: 'center', search: true, width: 100, fixed: true },
                    { name: 'scheme', index: 'scheme', align: 'center', search: true, stype: 'text', searchoptions: { sopt: ['cn'] } },
                    { name: 'dateTo', index: 'dateTo', align: 'center', search: false }
                ],
                grouping: true,
                groupingView: {
                    groupField: ['agentType'],
                    groupDataSorted: true,
                    groupColumnShow: false
                },
                // to save selection state
                onSelectAll: function (rowIds, status) {
                    if (status === true) {
                        for (var i = 0; i < rowIds.length; i++) {
                            selectedRows[rowIds[i]] = true;
                        }
                    } else {
                        for (var i = 0; i < rowIds.length; i++) {
                            delete selectedRows[rowIds[i]];
                        }
                    }
                },
                onSelectRow: function (rowId, status, e) {
                    if (status === false) {
                        delete selectedRows[rowId];
                    } else {
                        selectedRows[rowId] = status;
                    }

                },
                gridComplete: function () {
                    for (var rowId in selectedRows) {
                        agentsGrid.setSelection(rowId, true);
                    }
                }
            });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!