am trying to add jQuery Grid into my application(C# and Asp.net) using samples provided in some blogs, able to use Json data sent by Webservice. Now have tried to add pagination for the Grid and got strucked.Script is like this.
<script type="text/javascript">
$(function () {
$("#table").jqGrid({
datatype: function (pdata) { getData(pdata); },
height: 250,
colNames: ['ID', 'First Name', 'Last Name'],
colModel: [
{ name: 'ID', width: 60, sortable: false },
{ name: 'FirstName', width: 200, sortable: false },
{ name: 'LastName', width: 200, sortable: false }
],
imgpath: '<%= ResolveClientUrl("styles/redmon/images") %>',
pager: jQuery('#pager'),
rowNum: 2,
rowList: [2, 5, 10, 50, 100, 200, 500, 1000],
height: "100%",
viewrecords: true,
scrollOffset: 0,
caption: 'Sample'
});
});
function getData(pData) {
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
url: '<%= ResolveClientUrl("~/WebService.asmx/GetListOfPersons") %>',
data: '{}',
dataType: "json",
success: function (data, textStatus) {
if (textStatus == "success")
ReceivedClientData(JSON.parse(getMain(data)).rows);
},
error: function (data, textStatus) {
alert('An error has occured retrieving data!');
}
});
}
function ReceivedClientData(data) {
var thegrid = $("#table");
thegrid.clearGridData();
for (var i = 0; i < data.length; i++)
thegrid.addRowData(i + 1, data[i]);
}
function getMain(dObj) {
if (dObj.hasOwnProperty('d'))
return dObj.d;
else
return dObj;
}
</script>
...html block
<table id="table" cellpadding="0" cellspacing="0">
</table>
<div id="pager" class="scroll" style="text-align:center;"></div>
The Pager div is displayed and attached but isnt working am I missing something?
Thanks Samuel