Ver Mensaje Individual
  #3 (permalink)  
Antiguo 05/11/2013, 10:21
Avatar de BlinDer
BlinDer
 
Fecha de Ingreso: julio-2013
Mensajes: 52
Antigüedad: 10 años, 9 meses
Puntos: 0
Respuesta: Jqgrid, Paging y Struts

salida Json
Código Json:
Ver original
  1. {"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 original
  1. jQuery("#projectTable").jqGrid({
  2.         url: 'Almacen.do?do=cargaGrid',
  3.         datatype: 'json',
  4.         mtype: 'post',
  5.         jsonReader: {
  6.             root: "rows",
  7.             page: "page",
  8.             total: "total",
  9.             records: "records",
  10.             repeatitems: false,
  11.             cell: "cell",
  12.             id: "id"
  13.         },
  14.         sortable: true,
  15.         width: 685,
  16.         colNames: ['id', 'almacen', 'siglas', 'perfil', 'descripcion'],
  17.         colModel: [
  18.             {name: 'id', index: 'id', width: 110, hidden: true, key: false, align: "center"},
  19.             {name: 'almacen', index: 'almacen', width: 110, align: "center"},
  20.             {name: 'siglas', index: 'siglas', width: 90, align: "center"},
  21.             {name: 'descripcion', index: 'descripcion', width: 310, align: "center"},
  22.             {name: 'perfil', index: 'perfil', width: 130, align: "center"}
  23.         ],
  24.         rowNum: 10,
  25.         altRows: true,
  26.         multipleselect: true,
  27.         rowList: [10, 20, 40, 60, 80, 100],
  28.         pager: $('#pagingDiv'),
  29.         sortname: 'id',
  30.         sortorder: "asc",
  31.         rownumbers: false,
  32.         viewrecords: true,
  33.         caption: false,
  34.         ExpandColClick: true,
  35.         onSelectRow: function(rowid) {
  36.             var reg = $('#projectTable').jqGrid('getRowData', rowid);
  37.             EVTREG = reg.id;
  38. //          texto(EVTREG);
  39.         }
  40.     });
  41.     $('#projectTable').navGrid('#pagingDiv',
  42.             {refresh: true, edit: false, add: false, search: true, del: false},
  43.     {},
  44.             {},
  45.             {},
  46.             {multipleSearch: true,
  47.                 caption: 'Búsqueda...',
  48.                 sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge', 'bw', 'bn', 'ew', 'en', 'cn', 'nc']},
  49.     {}
  50.     );


Código Java:
Ver original
  1. almacendao = new AlmacenDAO();
  2.         List<Almacen> list_b = almacendao.selectTabla();
  3.         gson = new Gson();
  4.         int page = 4;
  5.         int total = 4;
  6.         int records = 35;
  7.         String formatoJSON = "{\"page\":\"" + page + "\",\"total\":\"" + total + "\",\"records\":\"" + records + "\",\"rows\":" + gson.toJson(list_b) + "}";
  8.         request.setAttribute("ajaxResponse", formatoJSON);
  9.         return mapping.findForward("jsonResponse");