<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: { 开发者_如何学Csopt: ['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: getDataType
parameter 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 using datatype: 'json'
and additional ajaxGridOptions
and serializeGridData
parameters.
If you do want to use "retro style" with datatype
as a function you can use postData
parameter and define getDataType
as function getDataType(postdata) {...
. The postdata
parameter contains all information which you need.
精彩评论