salida Json
Código Json:
Ver original{"page":"4","total":"4","records":"35","rows":[{"id":3,"siglas":"234234","perfil":"Gerente","almacen":"2342","descripcion":"34234234"},{"id":1,"siglas":"123123123","perfil":"Capturista","almacen":"123123","descripcion":"123123"},{"id":2,"siglas":"123123","perfil":"Capturista","almacen":"12312312","descripcion":"123123"},{"id":4,"siglas":"234234","perfil":"Capturista","almacen":"23423","descripcion":"4324234"}]}
Código Javascript
:
Ver originaljQuery("#projectTable").jqGrid({
url: 'Almacen.do?do=cargaGrid',
datatype: 'json',
mtype: 'post',
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
cell: "cell",
id: "id"
},
sortable: true,
width: 685,
colNames: ['id', 'almacen', 'siglas', 'perfil', 'descripcion'],
colModel: [
{name: 'id', index: 'id', width: 110, hidden: true, key: false, align: "center"},
{name: 'almacen', index: 'almacen', width: 110, align: "center"},
{name: 'siglas', index: 'siglas', width: 90, align: "center"},
{name: 'descripcion', index: 'descripcion', width: 310, align: "center"},
{name: 'perfil', index: 'perfil', width: 130, align: "center"}
],
rowNum: 10,
altRows: true,
multipleselect: true,
rowList: [10, 20, 40, 60, 80, 100],
pager: $('#pagingDiv'),
sortname: 'id',
sortorder: "asc",
rownumbers: false,
viewrecords: true,
caption: false,
ExpandColClick: true,
onSelectRow: function(rowid) {
var reg = $('#projectTable').jqGrid('getRowData', rowid);
EVTREG = reg.id;
// texto(EVTREG);
}
});
$('#projectTable').navGrid('#pagingDiv',
{refresh: true, edit: false, add: false, search: true, del: false},
{},
{},
{},
{multipleSearch: true,
caption: 'Búsqueda...',
sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge', 'bw', 'bn', 'ew', 'en', 'cn', 'nc']},
{}
);
Código Java:
Ver originalalmacendao = new AlmacenDAO();
List<Almacen> list_b = almacendao.selectTabla();
gson = new Gson();
int page = 4;
int total = 4;
int records = 35;
String formatoJSON
= "{\"page\":\"" + page
+ "\",\"total\":\"" + total
+ "\",\"records\":\"" + records
+ "\",\"rows\":" + gson.
toJson(list_b
) + "}"; request.setAttribute("ajaxResponse", formatoJSON);
return mapping.findForward("jsonResponse");