javascript - Loading a jqgrid table using jsonstring datatype - Stack Overflow

I would like to load a jqGrid table with a json String I produce from velocity; these are the table par

I would like to load a jqGrid table with a json String I produce from velocity; these are the table parameters:

var gridParams = {
    datatype: "jsonstring", 
    data: content,
    pager: $('#pagernav'), 
    rowNum: 5000,
    rownumbers: true,
    rowList: [50,100,200,500,1000,2000],
    ignoreCase: true,
    colNames: columns,
    colModel: tableColModel,
}

The values of content and columns, when printed on the console are:

[{"ID":"7", "fname":"Bob", "addr":"18" }, {"ID":"8", "fname":"Sue" }]
["ID", "fname", "addr"]

Indeed the grid is created with the right columns, but it is empty...what is wrong with what I wrote? Thanks for your answers.

I would like to load a jqGrid table with a json String I produce from velocity; these are the table parameters:

var gridParams = {
    datatype: "jsonstring", 
    data: content,
    pager: $('#pagernav'), 
    rowNum: 5000,
    rownumbers: true,
    rowList: [50,100,200,500,1000,2000],
    ignoreCase: true,
    colNames: columns,
    colModel: tableColModel,
}

The values of content and columns, when printed on the console are:

[{"ID":"7", "fname":"Bob", "addr":"18" }, {"ID":"8", "fname":"Sue" }]
["ID", "fname", "addr"]

Indeed the grid is created with the right columns, but it is empty...what is wrong with what I wrote? Thanks for your answers.

Share Improve this question asked Feb 8, 2013 at 13:35 user1012480user1012480 7522 gold badges12 silver badges25 bronze badges 5
  • It might be the missing addr in the second element in your data array. – Cerbrus Commented Feb 8, 2013 at 13:43
  • I tried, it doesn't change anything... – user1012480 Commented Feb 8, 2013 at 13:54
  • found another possibility: try using datastr: instead of data:. – Cerbrus Commented Feb 8, 2013 at 13:58
  • The pager is shown better now, but no signs of content... – user1012480 Commented Feb 8, 2013 at 14:04
  • Okay, then I'm out of guesses. Let's hope someone else can help you some more. – Cerbrus Commented Feb 8, 2013 at 14:06
Add a ment  | 

1 Answer 1

Reset to default 4

First of all more as 90% of usage of datatype: "jsonstring" is in case of usage jqGrid in wrong way. You don't describe your original problem more detailed, but I remend you to consider to use datatype: "json" instead of datatype: "jsonstring".

If you do really need to use datatype: "jsonstring" then you should provide input data using datastr option instead of data option used in case of datatype: "local".

Are the data from content are really JSON string (typeof content === "string") or you have the data as the object (typeof content === "string")? It seems to me that it's better to use in your case datatype: "local", data: content or datatype: "local", data: $.parseJSON(content) instead of usage datatype: "jsonstring", datastr: content, because the format of the input data is not standard required for datatype: "jsonstring" (see the documentation) so to be able to read the data successfully you will have to provide the corresponding jsonReader (see here an example)

In any way I would remend you to use gridview: true option, replace pager: $('#pagernav') to pager: '#pagernav' and to define key: true property for 'ID' column. Moreover you should alway include colModel in the text of the question. The text of colModel: tableColModel goes in the direction to the code $.jqGrid(myOptions) - if shows no required detailed which can be very important for finding solution of your problem.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745423197a4627059.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信