admin管理员组文章数量:1420993
I have this jqGrid. The following is my desired behavior:
- 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)
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.
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:
This answer suggests to use the onSelectRow and onSelectAll, but I was unable to implement. see fail
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:
- 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)
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.
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:
This answer suggests to use the onSelectRow and onSelectAll, but I was unable to implement. see fail
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
1 Answer
Reset to default 5here 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);
}
}
});
本文标签:
版权声明:本文标题:javascript - Make jqGrid multiselect selection persist following pagination, toolbar search, or filter - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745329827a2653760.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论