admin管理员组

文章数量:1420993

I have this jqGrid. The following is my desired behavior:

  1. The selected item will have the selection persist (and be rendered as such to the user) after changing pages or doing a search (toolbar or filter)
  2. When the select all button is selected, if no items on the current page are selected, it selects them all. If there is an item already selected, it will clear the entire list, whether on the page or not.

  3. When the Invoice Print button is clicked, it will either use the list of IDs that has been created as we go, or create a list of all IDS that have been selected, whether in the current display or not.

It would be acceptable if filter was not supported, but preferred.


To be sure, I know little about js, but here are some things that I have tried with mixed success:

  1. This answer suggests to use the onSelectRow and onSelectAll, but I was unable to implement. see fail

  2. This looks promising, but only will fix the pagination thing. So #1 looks like a prefered route. pastebin for question #2


P.S. back to the know little about js. in my project the alert and not shown functionality of the function select_ids does work, not sure why it is not displaying the alert in the jsfiddle. so sorry in advance that it needs repair, brownie points to however posts the forked fix.

grid.jqGrid({
            datatype: "local",
            data: mydata,
            colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
            colModel:[
                {name:'id',index:'id', key: true, width:70, sorttype:"int"},
                {name:'invdate',index:'invdate', width:90, sorttype:"date"},
                {name:'name',index:'name', width:100},
                {name:'amount',index:'amount', width:80, align:"right",sorttype:"float"},
                {name:'tax',index:'tax', width:80, align:"right",sorttype:"float"},
                {name:'total',index:'total', width:80,align:"right",sorttype:"float"},
                {name:'note',index:'note', width:150, sortable:false}
            ],
            search:true,
            pager:'#pager',
            jsonReader: {cell:""},
            rowNum: 10,
            rowList: [5, 10, 20, 50],
            sortname: 'id',
            sortorder: 'asc',
            viewrecords: true,
            multiSort: true, 
            multiselect: true, 

            height: "100%",
            caption: "Invoice Print"
        });
        grid.jqGrid('navGrid','#pager',{add:false,edit:false,del:false,search:true,refresh:true},
                    {},{},{},{multipleSearch:true, multipleGroup:true, showQuery: true});
        grid.jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false, defaultSearch:"cn"});

I have this jqGrid. The following is my desired behavior:

  1. The selected item will have the selection persist (and be rendered as such to the user) after changing pages or doing a search (toolbar or filter)
  2. When the select all button is selected, if no items on the current page are selected, it selects them all. If there is an item already selected, it will clear the entire list, whether on the page or not.

  3. When the Invoice Print button is clicked, it will either use the list of IDs that has been created as we go, or create a list of all IDS that have been selected, whether in the current display or not.

It would be acceptable if filter was not supported, but preferred.


To be sure, I know little about js, but here are some things that I have tried with mixed success:

  1. This answer suggests to use the onSelectRow and onSelectAll, but I was unable to implement. see fail

  2. This looks promising, but only will fix the pagination thing. So #1 looks like a prefered route. pastebin for question #2


P.S. back to the know little about js. in my project the alert and not shown functionality of the function select_ids does work, not sure why it is not displaying the alert in the jsfiddle. so sorry in advance that it needs repair, brownie points to however posts the forked fix.

grid.jqGrid({
            datatype: "local",
            data: mydata,
            colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
            colModel:[
                {name:'id',index:'id', key: true, width:70, sorttype:"int"},
                {name:'invdate',index:'invdate', width:90, sorttype:"date"},
                {name:'name',index:'name', width:100},
                {name:'amount',index:'amount', width:80, align:"right",sorttype:"float"},
                {name:'tax',index:'tax', width:80, align:"right",sorttype:"float"},
                {name:'total',index:'total', width:80,align:"right",sorttype:"float"},
                {name:'note',index:'note', width:150, sortable:false}
            ],
            search:true,
            pager:'#pager',
            jsonReader: {cell:""},
            rowNum: 10,
            rowList: [5, 10, 20, 50],
            sortname: 'id',
            sortorder: 'asc',
            viewrecords: true,
            multiSort: true, 
            multiselect: true, 

            height: "100%",
            caption: "Invoice Print"
        });
        grid.jqGrid('navGrid','#pager',{add:false,edit:false,del:false,search:true,refresh:true},
                    {},{},{},{multipleSearch:true, multipleGroup:true, showQuery: true});
        grid.jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false, defaultSearch:"cn"});
Share Improve this question edited May 23, 2017 at 12:16 CommunityBot 11 silver badge asked Aug 29, 2013 at 4:57 David__David__ 3752 gold badges6 silver badges20 bronze badges 3
  • Any success? I have absolutely the same task – Pavel Voronin Commented Feb 3, 2014 at 14:14
  • No not yet, no suggestions and I'm not seeing it, so kind of back-burnered for now. – David__ Commented Feb 18, 2014 at 17:02
  • I played a little with jqgrid and managed to do what is needed. Will give you the link tomorrow – Pavel Voronin Commented Feb 18, 2014 at 18:46
Add a ment  | 

1 Answer 1

Reset to default 5

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);
                    }
                }
            });

本文标签: