I'm looking to find the best way to allow users to choose to show ALL records in a jqGrid. I know that a -1 value passed for the rows parameter denotes ALL, but I want the word "ALL" not a -1 to appear in the rowList select element, ie. rowList: [15, 50, 100, 'ALL'].
I'm passing the grid request to a web service which accepts an int for "rows", and I'm trying find how and when I should change the user selected value of "ALL" to a -1 before it gets sent to the web service.
Below is my cleaned up grid code. I tried some various code blocks before my $.ajax in the datatype function. But most attempts just seemed like I have to be doing this the most convoluted way I possibly could. For example,
datatype: function(postdata) {
if ($("#gridTableAssets").jqGrid('getGridParam', 'rowNum') == 'ALL') {
$("#gridTableAssets").appendPostData({ "rows": -1, "page": 1 });
}
$.ajax({...
But doing that seemed to cause the actual "page" GridParam to be nulled out on subsequent grid actions, forcing me handle that in other places. There just seems like this is something that would be frequently done out there and have clean way of doing it.
Cleaned grid code:
$("#gridTableAssets").jqGrid({
datatype: function(postdata) {
$.ajax({
url: "/Service/Repository.asmx/GetAssets",
data: JSON.stringify(postdata),
type: 'POST',
contentType: "application/json; charset=utf-8",
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert('error');
},
success: function(msg) {
var assetsGrid = $("#gridTableAssets")[0];
assetsGrid.addJSONData(JSON.parse(msg));
...
}
});
},
...
pager: $('#pagerAssets'),
rowNum: 15,
rowList: [15, 50, 100, 'ALL'],
...
onPaging: function(index, colindex, sortorder) {
SessionKeepAlive();
}
});
And here is the web service
[WebMethod]
public string GetAssetsOfAssetStructure(bool _search, int rows, int page,
string sidx, string sord, string filters)