I have a problem where I need to display json data on a jqgrid. The data I get is of the following format:
{"data":{"data":"\tat org.aaa.aaa.aaa.aaa.aaa.aaa(aaa.java:512)[147:org.aaa.aaa.aaa:9.1.1]\n\tat aaa.aaa.aaa.aaa.aaa.aaa(aaa.java:1789)[146:org.aaa:9.1.1]\n"}}
My javascript to display the data is:
$("#grid").jqGrid({
url: '/getdata',
datatype: "json",
mtype: "GET",
colNames:['data'],
colModel:[
{name:'data', index:'data', align:'center'}
],
jsonReader : {
repeatitems: false,
id: "0",
cell: "",
root: "logs",
page: function() { return 1; },
total: function() { return 1; },
records: function(obj) { return obj.length; }
},
loadonce: true,
viewrecords: true,
autowidth: true,
multiselect: false,
ignoreCase: true,
sortable: true,
height: 600,
rowNum: 999
});
I tried a few combinations, but could not get the data to be displayed on the jqgrid with this code. The jqgrid displays an empty table. I guess I am missing something here.
I also have to format the data so that every time we hit ‘\n’, we display it in a new row. I guess I can use ‘addrowdata’ in the formatter for the column to do that. Is that right?
Any pointers are greatly appreciated.
thanks,
Asha
I don’t recommend you to use
addRowData. It’s more effectively to usebeforeProcessingto modify the data returned from the server to the format which jqGrid can read. You can for example to split thedata.datapart by\nand fill the array of the corresponding items:I included the call of jQuery.trim in the above code to remove unneeded
\tor other white space characters at the beginning or at the end of every line.I included additionally
autoencode: trueoption which is strict recommended to be sure that the texts which included special characters for HTML (like<,>,&and so on) will be correctly displayed inside of the grid.Additionally you should change
jsonReaderto for example the followingThe value of
idseems tricky, but the implementation generate really unique values foridattribute of every line.The corresponding demo you will find here.