I am trying to dynamically add rows to my jqGrid dependent on a value a user has put into a textbox. There is a method which fetches a Json request from the server but I am having problems getting it to add the actual data.
Here is the jqGrid code:
function RenderGrid(grid) {
$("#queryGrid").jqGrid({
datatype: grid.DataType,
mtype: grid.RequestType,
colNames: grid.ColumnNames,
colModel: grid.ColumnModel,
pager: $('#pager'),
rowNum: grid.MaxViewableRows,
caption: "Search",
width: grid.Width,
rowList: grid.MaxViewableRowOptions,
height: grid.Height,
loadtext: "Please wait...",
viewrecords: grid.ShowTotalRecords,
hidegrid: grid.HideEnabled,
forceFit: true
})
I have not set the URL option because, as I mentioned previously, the data is coming from elsewhere. However this is the colModel:
{"name":"id","index":"id","hidden":"true"},
{"name":"Customer","index":"Customer","sorttype":"Int32","editable":false,"width":216,"resizable":true},
{"name":"ShortName","index":"ShortName","sorttype":"String","editable":false,"width":216,"resizable":true},
{"name":"CorrespondenceName","index":"CorrespondenceName","sorttype":"String","editable":false,"width":216,"resizable":true}
Here is the code which gets the JSON:
function SearchGrid() {
$.ajax({
url: $.url("/MyController/MyAction"),
type: "POST",
dataType: "json",
data: {
Name: $('#Name').val(),
Fields: $('#Fields').text(),
},
success: ApplyDataToGrid //More on this later in the question
});
}
How this all seemenly works fine. I don't think the issue is with any of the above code. Here is where it gets tricky, this is where I get the JSON object and when I attempt to add it to the grid.
This is the JSON I get back:
{"page":1,"records":1,"rows":[{"id":1,"cell":[94,"DAMIEN","IS AN IDIOT"]}],"total":1}
This is the code I use to (attempt) to add the data onto the grid:
function ApplyDataToGrid(data) {
$("#queryGrid")[0].addJSONData(data, $("#queryGrid").bDiv, 0)
}
or
function ApplyDataToGrid(data) {
$("#queryGrid")[0].addJSONData(data)
}
This does apply the page count and record count but it doesn't display the row which should add the ID and the three columns!
Any idea? It's driving me crazy! Thanks in Advance, Damien