jqGrid暴露了一个属性rowNum
,您可以设置每页显示的行数。如何将网格设置为仅显示所有行?
目前,我只是将rowNum
设置为非常高的值,例如<%= int.MaxValue %>
,但我想知道是否有更好的方法。
jqGrid暴露了一个属性rowNum
,您可以设置每页显示的行数。如何将网格设置为仅显示所有行?
目前,我只是将rowNum
设置为非常高的值,例如<%= int.MaxValue %>
,但我想知道是否有更好的方法。
rowNum: -1
rowNum
设置为非常大的数字,以模拟-1
的行为。rowNum:''
。但是,我尝试在包含本地数据(loadonce:true
)的网格上使用此方法。尝试对行进行排序时,所有网格的本地数据都会消失。因此,这个解决方案似乎不适用于具有本地数据的网格,除非这个缺陷已经在jqGrid的较新版本中得到修复(我在jqGrid 3.8.2上测试了它)。如果您有反馈,请在下面发表评论!jqgrid(无论是3.5版本还是其他版本)似乎没有一种优雅的内置方法来完成此操作。到目前为止,我找到的最好方法是将以下内容添加到您的网格选项中:
rowList:[10,20,30,100000000],
loadComplete: function() {
$("option[value=100000000]").text('All');
},
其中100000000是一个任意大于你将返回的最大行数的数字,而option[value=]这一行则是为了使你的用户界面看起来更好看一些。有点丑陋,但对我来说有效。
这个可以运行:
// Step1 - defines the rows
jqGridOptions.rowList =[10, 50, 100, 500, 'All'];
...
...
// Step2 - Change the 'All' to a meaningful value
loadComplete: function (data) {
$(".ui-pg-selbox option[value='All']").val(1000);
}
如果您不想使用分页,那么只需更改您的服务器端代码以返回所有行即可,不要使用rows参数。
如果您想要有rowlist选项,但也想要显示所有选项,则可以在网格属性中执行以下操作:
jQuery("#statement_mods").jqGrid({
rowList:['ALL',30,50,100,200]
});
然后在服务器端的代码中,确保如果GET['rows']='ALL',则忽略行参数。
对我来说,设置 rowNum:-1
就可以解决问题了。
// Get the total number of rows and delete space between numbers (Split the content of the div depending of the language (for me french)
var val=jQuery("#pager_right div").text().split('sur')[jQuery("#pager_right div").text().split('sur').length-1].split(' ').join('');
// And do the appending if the option isn't already added
if(!$(".ui-pg-selbox option[value='"+val+"']").length > 0)
jQuery(".ui-pg-selbox").append($('<option></option>').val(val).html(val));
// To over come with this problem ,you can just write the bold mark
(rowNum:10000,):
$("#MasterDataDefinationGrid").jqGrid({
url: 'FetchData.aspx/GetDataFromDB',
datatype: 'json',
mtype: 'POST',
height: 300,
autowidth: true,
serializeGridData: function (postData) {
return JSON.stringify(postData);
},
ajaxGridOptions: { contentType: "application/json" },
loadonce: true,
colNames: [Your column names],
colModel: [Your model],
formatter: 'actions',
pager: '#MasterDataDefinationPager', pgbuttons: false,pgtext:false,
multiselect: false,
ignoreCase: true,
**rowNum: 10000,**
loadtext: 'Loading ...',
gridview: true,
hidegrid: false,
jsonReader: {
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.d.length; },
root: function (obj) { return obj.d; },
repeatitems: false,
id: "0"
},
caption: 'Data'
});
$('#bla').jqGrid({
...
'rowNum' : 0,
'loadOnce' : true,
'loadComplete': function(data) {
$(this).jqGrid('setGridParam', 'rowNum', data.total);
},
...
});
loadOnce
选项。请注意,如果您不设置rowNum
选项为0,则默认显示20条记录。
此外,我假定您以文档中记录的JSON读取器格式从服务器返回总行数。Jqgrid.PagerSettings.PageSize = Max Row you want to display;
Jqgrid.ToolBarSettings.ToolBarPosition = ToolBarPosition.Hidden;
设置 rowNum: '' 将获取所有行。