views:

40

answers:

1

Hello... I have a jqgrid where in I am returning a list of objects from the controller... I have used the List collection interface of java.util package.... and returning that...

@RequestMapping("task-management.html")
public @ResponseBody List<TaskBean> getStatus()
{
    System.out.println("\nin task mgmt controller");
    taskList.add(new TaskBean("Task1", "K-CY-329", "144", "G-3", "1", "Pending", "XYZ"));
    taskList.add(new TaskBean("Task2", "K-CY-356", "165", "A-10", "4", "Closed", "ABC"));
    taskList.add(new TaskBean("Task3", "K-CY-343", "768", "B-12", "3", "Pending", "IJK"));
    taskList.add(new TaskBean("Task4", "K-CY-786", "918", "F-9", "2", "Open", "PQR"));
    return taskList; 
}

and i have given the corresponding in jqgrid's url with datatype set to json.... I am using spring mvc3.0 controller.... this controller function gets called successfully.... But i cant see the TaskBean objects getting rendered to the jqgrid.... Please help!!!

A: 
$("#task-list-table").jqGrid({
    autowidth: true,
    datatype : "json",
    url: "task-management.html",
    mtype: 'POST',
    colNames : ["Title","Order ID","Realty","Building",
                "Priority","Action","Assignee"],
    colModel : [
        {label: "Title",   name: "title",   index: "Title"},
        {label: "OrderID", name: "orderId", index: "OrderID", jsonmap: "orderId"},
        {label: "Realty",  name: "realty",  index: "Realty",  jsonmap: "realty" },
        {label: "Building",name: "building",index: "Building",jsonmap: "building"},
        {label: "Priority",name: "priority",index: "Priority",jsonmap: "priority"},
        {label: "Action",  name: "action",  index: "Action",  jsonmap: "action"  },
        {label: "Assignee",name: "assignee",index: "Assignee",jsonmap: "assignee"}
    ],
    sortname : "Title",
    sortorder : "desc",
    shrinkToFit: true,
    viewrecords: true,
    jsonReader : {
        repeatitems : false
    },
    onSelectRow: function(){
        alert(jQuery("#task-list-table").getGridParam('selrow'));
    });
apoorvabade
It is strange, that the *url* which gives JSON data back the extension **html** hat.
Oleg
The javascript code should have one more } before ');' at the end of your code. Is it exist in the original code?
Oleg
ok i got the problem.... My JSON object that gets returned only contains the data that is required for the 'rows' values in the expected json format for JQGrid.... i need to customize this using some libraries at the server side... and then i need to send them....
apoorvabade
here in this scenario, i need to format my json object coming from the controller in such a way so that it is compatible with the jsonreader of jqgrid... Is there a way to do this?
apoorvabade
With respect of custom `jsonReader` you are able to read practical any information which are send from the server. To be more concrete you should place the corresponding new question. With respect of Fiddler tool (see http://www.fiddler2.com/fiddler2/) or Firebug (see http://getfirebug.com/) you can easy to catch the JSON data send back from the server to the jqGrid. Posting the data (you can leave one-two rows of data in the JSON text) helps to suggest the `jsonReader` which will solve the problem.
Oleg