我有这个jqGrid http://jsfiddle.net/david_c/mUMGs/3/。以下是我想要的行为:
- 更改页面或执行搜索(工具栏或过滤器)后,选定的项目将保留选择(并如此呈现给用户)
当选择全选按钮时,如果当前页面上没有选择任何项目,则会选择所有项目。如果已经选择了一个项目,它将清除整个列表,无论是否在页面上。
单击“发票打印”按钮时,它将使用已创建的 ID 列表,或创建已选择的所有 IDS 的列表,无论是否在当前显示中。
如果不支持过滤器也是可以接受的,但这是首选。
可以肯定的是,我对 js 知之甚少,但以下是我尝试过的一些事情,但效果参差不齐:
This answer https://stackoverflow.com/questions/4710780/jqgrid-multiselect-only-selects-rows-on-the-current-page-if-paging-is-enabled建议使用onSelectRow和onSelectAll,但我无法实现。see fail http://jsfiddle.net/david_c/ECtVw/
This http://www.trirand.com/blog/?page_id=393/help/maintaining-checkbox-selections-through-a-page-operation/看起来很有希望,但只能解决分页问题。所以#1 看起来像是首选路线。问题#2的pastebin http://pastebin.com/1Yyf07xA
附:回到对js了解甚少。在我的项目中,函数 select_ids 的警报和未显示的功能确实有效,不知道为什么它不在 jsfiddle 中显示警报。提前抱歉,它需要修复,布朗尼指出,但是发布了分叉修复。
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"});