我有一个 jqGrid,它有服务器端数据,有 10 万行。我使用 jqGrids native multiselect = true
,然后在各种 jqgrid 事件上推送/拼接选定行的 id ......所有这些都很完美。我想更进一步,并有一个“查看所选”选项,用户可以选择该选项将以编程方式创建一个过滤器,以仅显示在我的所选行数组中包含 id 的行。
因此,如果用户在选择“查看已选择”选项时选择了 10,000 行中的 125 行,我将创建一个过滤器以仅显示在我的所选行数组中具有 id 的 125 行。
尝试了几种方法来显示选择而不过滤,通过隐藏行但遇到了用户在第 57 页上选择行的问题......然后他们选择“查看所选”,然后查看所选内容的唯一方法是导航到页面57.
dataformat=json
尝试在和...之间切换,dataformat=local
但这让我对 jqGrid 代码中的 sType 过滤方式感到头疼。
如果有人有办法创建这个神奇的过滤器......或者对选定的服务器端数据进行过滤/排序的更好方法,我们将不胜感激。
我为我们从网格创建中删除的丑陋格式道歉,我们不漂亮地打印它=)
var selectedIDs = [], viewSelectedOnly = false;
var WrapperDivID = $('#grid_wrapper'),
GridDivID = $('#BatchBatchGrid');
//used to help us get gridid out for shiftclick of header
WrapperDivID.attr('data-id', '120');
var _AppType = Enum.GridArray(Enums.Security_ApplicationType);
$(document).ready(function () {
GridDivID.jqGrid({
colNames:[
'LocationID'
,
'ChannelID'
,
'Post'
,
'Actions'
,
'ID'
,
'Posted'
,
'Channel'
,
'StoreCode'
,
'Location'
,
'Reference#'
,
'Remote Ref#'
,
'Open Date'
,
'Close Date'
,
'Sales + Tax'
,
'Status'
,
'Register #'
],
colModel:
[
{
name:
'Account_Location.ID'
,
index:
'Account_Location.ID'
,
width:
10 ,
align:
'left'
,
hidden:
true }
,
{
name:
'Channel_Channel.ID'
,
index:
'Channel_Channel.ID'
,
width:
10 ,
align:
'left'
,
hidden:
true }
,
{
name:
'Post'
,
index:
'Post'
,
width:
5 ,
align:
'center'
,
search:
false ,
sortable:
false ,
hidden:
true }
,
{
name:
'Action'
,
index:
'Action'
,
width:
10 ,
align:
'center'
,
search:
false ,
sortable:
false }
,
{
name:
'ID'
,
index:
'ID'
,
width:
10 ,
align:
'left'
,
hidden:
true }
,
{
name:
'Posted'
,
index:
'Batch_Batch.Posted'
,
width:
10 ,
align:
'left'
,
search:
true ,
stype:
'select'
,
searchoptions:
'{value: ddPosted }'
}
,
{
name:
'Channel_Channel.Name'
,
index:
'Channel_Channel.Name'
,
width:
15 ,
align:
'left'
}
,
{
name:
'Account_Location.StoreCode'
,
index:
'Account_Location.StoreCode'
,
width:
7 ,
align:
'left'
}
,
{
name:
'Account_Location.Name'
,
index:
'Account_Location.Name'
,
width:
40 ,
align:
'left'
}
,
{
name:
'BatchNumber'
,
index:
'Batch_Batch.BatchNumber'
,
width:
15 ,
align:
'left'
}
,
{
name:
'RemoteReferenceNumber'
,
index:
'RemoteReferenceNumber'
,
width:
15 ,
align:
'left'
}
,
{
name:
'OpeningTime'
,
index:
'OpeningTime'
,
width:
15 ,
align:
'left'
}
,
{
name:
'ClosingTime'
,
index:
'ClosingTime'
,
width:
15 ,
align:
'left'
,
search:
'true'
}
,
{
name:
'SalesPlusTax'
,
index:
'SalesPlusTax'
,
width:
15 ,
align:
'left'
}
,
{
name:
'Status'
,
index:
'Batch_Batch.Open'
,
width:
15 ,
align:
'left'
,
search:
true ,
stype:
'select'
,
searchoptions:
'{value:ddStatuses}'
}
,
{
name:
'RegisterNumber'
,
index:
'RegisterNumber'
,
width:
15 ,
align:
'left'
}
],
pager :$('#pager') ,
rowNum :"50"
,
rowList :[10,20,50,100] ,
sortname :'Batch_Batch.Closingtime'
,
sortorder :"desc"
,
viewrecords :true ,
url :'../Grid/BatchBatchGetData'
,
datatype :'json'
,
mtype :'GET'
,
autowidth :true ,
autoheight :true ,
height :400 ,
multiselect :true ,
rownumbers :true ,
gridComplete: function(){
var ids = GridDivID.jqGrid('getDataIDs');
for(var i = 0; i < ids.length; i ++){
var id = ids[i];
var link = '<a href="../Accounting/BatchView?BatchID=' + id + '" target="_new">View</a>';
GridDivID.jqGrid('setRowData',id,{Action:link});
if (viewSelectedOnly) {
if(selectedIDs.indexOf(id) === -1){
$('#' + id).css('display','none');
}
}
}
var curr_width = WrapperDivID.width();
GridDivID.jqGrid('setGridWidth', curr_width);
},
onSelectRow: function(id, status){
var p = this.p, item = $(this).getRowData(id), _index = selectedIDs.indexOf(id);
if(status){
if(selectedIDs.indexOf(id) === -1)
selectedIDs.push(id);
}else{
selectedIDs.splice(_index, 1);
}
},
loadComplete: function(gridData){
var p = this.p, data = p.data, item, grid = $(this), index = p._index, rowid, i, selCount;
//Logic for view selected
if (gridData.rows.length > 0) {
for (var i = 0; i < gridData.rows.length; i++) {
if(selectedIDs.indexOf(gridData.rows[i].id) !== -1){
grid.jqGrid('setSelection', gridData.rows[i].id, true);
}
}
}
},
onSelectAll: function(aRowids,status){
var p = this.p;
for (var i = 0; i < aRowids.length; i++) {
var _index = selectedIDs.indexOf(aRowids[i])
if(status){
if(selectedIDs.indexOf(aRowids[i]) === -1)
selectedIDs.push(aRowids[i]);
}else{
selectedIDs.splice(aRowids[i], 1);
}
}
}
}); //Ends jqGrid instantiation
GridDivID.jqGrid('navGrid','#pager',{del:false,add:false,edit:false,search:true},{closeAfterAdd: true,closeAfterEdit: true},{closeAfterAdd: true,closeAfterEdit: true});
GridDivID.jqGrid('filterToolbar',{stringResult: true,searchOnEnter:true});
//GridDivID.jqGrid('gridResize',{minWidth:350,minHeight:100});
}); //Ends Document Ready