<table id="UsersGrid"></table>
<script type="text/javascript">
$(document).ready(function () {
$('#UsersGrid').jqGrid({
colNames: ['Online', 'Computer', 'IP', 'User'],
colModel: [
{ name: 'IsOnline', width: 100, index: 'IsOnline', searchoptions: { sopt: ['eq', 'ne']} },
{ name: 'Name', index: 'Name', searchoptions: { sopt: ['eq', 'ne', 'cn']} },
{ name: 'IP', index: 'IP', searchoptions: { sopt: ['eq', 'ne', 'cn']} },
{ name: 'User', index: 'User', searchoptions: { sopt: ['eq', 'ne', 'cn']} }
],
height: 250,
datatype: getDataType
});
});
function getDataType() {
var grid = $("#UsersGrid");
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/GridTest/GridTestService.asmx/GetData",
data: jqGridSettings(grid),
dataType: "json",
success: function (response) {
jqGridDataReceived(response.d, grid);
}
});
}
function jqGridSettings(grid) {
return "{}";
var settings = {
};
return JSON.stringify(settings);
}
function jqGridDataReceived(json, grid) {
var rows = JSON.parse(json).rows;
grid.clearGridData();
for (var i = 0; i < rows.length; i++) {
grid.addRowData(i + 1, rows[i]);
}
}
</script>
I want to pass the original search parameters to the server-side, how can I retrieve them with javascript?
Namely, where can I get the grid’s postData?
It seems to me that the origin of the problem which you try to solve is the
datatype: getDataTypeparameter which you use. You use some very old code example from the time of vary old jqGrid versions. Look at here for an example how you can call ASMX web service usingdatatype: 'json'and additionalajaxGridOptionsandserializeGridDataparameters.If you do want to use “retro style” with
datatypeas a function you can usepostDataparameter and definegetDataTypeasfunction getDataType(postdata) {.... Thepostdataparameter contains all information which you need.