Pessoal, como posso fazer para formatar o retorno da chamada de algum metódo antes de serealizar?
O JQGrid (jquery) espera um retorno especifico de JSON
Exemplo:
{
“page”: 1,
“total”: 1,
“records”: 11,
“rows”: [
{“id”: 1, “cell”: [“1”, “Super Item”, “300”, 0, null, false, false]},
{“id”: 2, “cell”: [“2”, “Item 1”, “100”, 1, 1, false, false]},
{“id”: 3, “cell”: [“3”, “Sub Item 1”, “50”, 2, 2, true, true]},
{“id”: 4, “cell”: [“4”, “Sub Item 2”, “25”, 2, 2, false, false]},
{“id”: 5, “cell”: [“5”, “Sub-sub Item 1”, “25”, 3, 4, true, true]},
{“id”: 6, “cell”: [“6”, “Sub Item 3”, “25”, 2, 2, true, true]},
{“id”: 7, “cell”: [“7”, “Item 2”, “200”, 1, 1, false, false]},
{“id”: 8, “cell”: [“8”, “Sub Item 1”, “100”, 2, 7, false, false]},
{“id”: 9, “cell”: [“9”, “Sub-sub Item 1”, “50”, 3, 8, true, true]},
{“id”: 10, “cell”: [“10”, “Sub-sub Item 2”, “50”, 3, 8, true, true]},
{“id”: 11, “cell”: [“11”, “Sub Item 2”, “100”, 2, 7, true, true]}
]
}
Quando eu executo a minha chamada o mesmo retorna JSON puro:
@Get @Path("/produtos/gustavo")
public void buscaJqGrid() {
result.use(json())
.from(dao.getLista())
.serialize();
}
Precisaria incluir dados antes de serealizar o JSON
"page": 1,
“total”: 1,
“records”: 11,
“rows”: [
Estou no caminho certo?
Meu código JQGrid:
jQuery("#list2").jqGrid({
url:'http://localhost:8080/vraptor1/produtos/gustavo',
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
datatype: "json",
mtype: "POST",
colNames:['ID','Nome', 'Descrição', 'Preço'],
colModel:[
{name:'id',index:'id', width:25},
{name:'nome',index:'nome', width:90},
{name:'descricao',index:'descricao', width:200},
{name:'preco',index:'preco', width:80, align:"right"}
],
rowNum:10,
rowList:[10,20,30],
pager: '#pager2',
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption:"JSON Example"
});
jQuery("#list2").jqGrid('navGrid','#pager2',{edit:false,add:false,del:false});