0

The error occurs when returning the JSON data for jqGrid.

See Config a colModel my Jqgrid:

        colModel:[
                    {name:'NUM_PEDIDO', index:'NUM_PEDIDO', width:80, align:"center", key: true},
                    {name:'NOM_SITUACAO', index:'NOM_SITUACAO', width:70, align:"center"},
                    {name:'QTD_ANEXO', index:'QTD_ANEXO', width:55, align:"center"},
                    {name:'COD_PRESTADOR', index:'COD_PRESTADOR', width:90, align:"center"},
                    {name:'DATA_AUTORIZACAO', index:'DATA_AUTORIZACAO', width:90, align:"center"},
                    {name:'ITEM_MEDICO', index:'ITEM_MEDICO', width:110, align:"center"},
                    {name:'COD_DENTE_REGIAO', index:'COD_DENTE_REGIAO', width:110, align:"center"},
                    {name:'IND_FACE_LP', index:'IND_FACE_LP', width:30, align:"center"},
                    {name:'IND_FACE_V', index:'IND_FACE_V', width:15, align:"center"},
                    {name:'IND_FACE_M', index:'IND_FACE_M', width:15, align:"center"},
                    {name:'IND_FACE_D',index:'IND_FACE_D', width:15, align:"center"},
                    {name:'IND_FACE_OI', index:'IND_FACE_OI', width:30, align:"center"},
                    {name:'IND_SITUACAO', index:'IND_SITUACAO', width:60, align:"center"},
                    {name:'COD_GLOSA_PRIORIDADE_AUT', index:'COD_GLOSA_PRIORIDADE_AUT', width:50, align:"center"},
                    {name:'NUM_GUIA', index:'NUM_GUIA', width:75, align:"center"},
                    {name:'TIPO_SITUACAO', index:'TIPO_SITUACAO', width:100, align:"center"},
                    {name:'DAT_REALIZACAO', index:'DAT_REALIZACAO', width:100, align:"center"},                                        
                    {name:'NOME_SITUACAO_PGTO', index:'NOME_SITUACAO_PGTO', width:100, align:"center"},
                    {name:'COD_GLOSA_PRIORIDADE_PGTO', index:'COD_GLOSA_PRIORIDADE_PGTO', width:100, align:"center"},
                    {name:'DT_PAGAMENTO', index:'DT_PAGAMENTO', width:100, align:"center"},
                    {name:'IND_SITUACAO_REV', index:'IND_SITUACAO_REV', width:135, align:"center"},
                    {name:'COD_GLOSA_PRIORIDADE_REVISAO', index:'COD_GLOSA_PRIORIDADE_REVISAO', width:120, align:"center"}

See JSON:

{"Items":[{"page":1,"total":1,"records": 4 ,"items":[ { "NUM_PEDIDO":"8476",  "NOM_SITUACAO":"Autorizado",  "QTD_ANEXO":"0",  "COD_PRESTADOR":"11067322",  "DATA_AUTORIZACAO":"28/10/2013",  "ITEM_MEDICO":"85100226",  "COD_DENTE_REGIAO":"35",  "IND_FACE_LP":"S",  "IND_FACE_V":"S",  "IND_FACE_M":"S",  "IND_FACE_D":"S",  "IND_FACE_OI":"",  "IND_SITUACAO":"A",  "COD_GLOSA_PRIORIDADE_AUT":"0",  "NUM_GUIA":"",  "TIPO_SITUACAO":"",  "DAT_REALIZACAO":"",  "NOME_SITUACAO_PGTO":"",  "COD_GLOSA_PRIORIDADE_PGTO":"0",  "DT_PAGAMENTO":"",  "IND_SITUACAO_REV":"",  "COD_GLOSA_PRIORIDADE_REVISAO":"0"},{ "NUM_PEDIDO":"8476",  "NOM_SITUACAO":"Autorizado",  "QTD_ANEXO":"0",  "COD_PRESTADOR":"11067322",  "DATA_AUTORIZACAO":"28/10/2013",  "ITEM_MEDICO":"85100226",  "COD_DENTE_REGIAO":"35",  "IND_FACE_LP":"S",  "IND_FACE_V":"S",  "IND_FACE_M":"S",  "IND_FACE_D":"S",  "IND_FACE_OI":"",  "IND_SITUACAO":"A",  "COD_GLOSA_PRIORIDADE_AUT":"0",  "NUM_GUIA":"",  "TIPO_SITUACAO":"",  "DAT_REALIZACAO":"",  "NOME_SITUACAO_PGTO":"",  "COD_GLOSA_PRIORIDADE_PGTO":"0",  "DT_PAGAMENTO":"",  "IND_SITUACAO_REV":"",  "COD_GLOSA_PRIORIDADE_REVISAO":"0"},{ "NUM_PEDIDO":"8476",  "NOM_SITUACAO":"Autorizado",  "QTD_ANEXO":"0",  "COD_PRESTADOR":"11067322",  "DATA_AUTORIZACAO":"28/10/2013",  "ITEM_MEDICO":"85100226",  "COD_DENTE_REGIAO":"35",  "IND_FACE_LP":"S",  "IND_FACE_V":"S",  "IND_FACE_M":"S",  "IND_FACE_D":"S",  "IND_FACE_OI":"",  "IND_SITUACAO":"A",  "COD_GLOSA_PRIORIDADE_AUT":"0",  "NUM_GUIA":"",  "TIPO_SITUACAO":"",  "DAT_REALIZACAO":"",  "NOME_SITUACAO_PGTO":"",  "COD_GLOSA_PRIORIDADE_PGTO":"0",  "DT_PAGAMENTO":"",  "IND_SITUACAO_REV":"",  "COD_GLOSA_PRIORIDADE_REVISAO":"0"},{ "NUM_PEDIDO":"8476",  "NOM_SITUACAO":"Autorizado",  "QTD_ANEXO":"0",  "COD_PRESTADOR":"11067322",  "DATA_AUTORIZACAO":"28/10/2013",  "ITEM_MEDICO":"85100226",  "COD_DENTE_REGIAO":"35",  "IND_FACE_LP":"S",  "IND_FACE_V":"S",  "IND_FACE_M":"S",  "IND_FACE_D":"S",  "IND_FACE_OI":"",  "IND_SITUACAO":"A",  "COD_GLOSA_PRIORIDADE_AUT":"0",  "NUM_GUIA":"",  "TIPO_SITUACAO":"",  "DAT_REALIZACAO":"",  "NOME_SITUACAO_PGTO":"",  "COD_GLOSA_PRIORIDADE_PGTO":"0",  "DT_PAGAMENTO":"",  "IND_SITUACAO_REV":"",  "COD_GLOSA_PRIORIDADE_REVISAO":"0"}, ]}]}
cavalsilva
  • 193
  • 13

1 Answers1

1

You don't posted more full code which you use. The format of the input JSON data which you use is other as default expected by jqGrid (see the documentation). So you have to specify jsonReader option like below to inform jqGrid here it can get the required information:

jsonReader: {
    root: "Items.0.items",
    page: "Items.0.page",
    total: "Items.0.total",
    records: "Items.0.records",
    repeatitems: false
}

I would recommend you additionally to remove all index properties from colModel and remove common align:"center" property. Default value of align is "left". If you have colModel with more columns with another orientation you should change the defaults by jqGrid option

cmTemplate: { align: "center" }

In the case you can remove align:"center" property from all colModel items. See the answer for more information.

UPDATED: The demo demonstrate that the above jsonReader can read the data which you posted. Additional modification which I made in your data: 1) I removed , after the last item. 2) I modified value of NUM_PEDIDO property in JSON data to make the data unique (you use key: true from NUM_PEDIDO column which mean that the column contains unique values).

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • See my jsonReader jsonReader: { repeatitems: false, root: function (obj) { return obj.Items[0].items; }, page: function (obj) { return obj.Items[0].page; }, total: function (obj) { return obj.Items[0].total; }, records: function (obj) { return obj.Items[0].records; } } – cavalsilva Jan 16 '14 at 14:17
  • @cavalsilva: you should include **more full JavaScript code which you use**. The options `datatype`, `loadonce`, `jsonReader` are very important. It's important to know how you fill the grid. Do you use `datatype: "json"` and the JSON data which you posted are from the server response or you use `datatype: "local"` or `dadatype: "jsonstring"`? You should don't post any important information in comments. Instead of that you should click on "edit" link below your question, modify/append the text of your question and post comment to inform other about your modifications. – Oleg Jan 16 '14 at 14:26
  • I remove all index and align and the error continued, I use datatype:"json". – cavalsilva Jan 16 '14 at 14:27
  • @cavalsilva: correct `jsonReader` should solve your problem. Other suggestion only for reducing your code and making it more readable. If your problem not solved then you don't posted important part of your JavaScript code in your question. – Oleg Jan 16 '14 at 14:30
  • @cavalsilva: Do you reduced your original JSON response to 4 items manually? The JSON data which you posted are wrong because of `,` after the 4-th (the last) item (see `}, ]}]}`). – Oleg Jan 16 '14 at 14:32
  • **My default jsonReader with jqgrid null** {"Items":[{"page":1,"total":0,"records":0,"items":[]}]} **My jsonReader is there:** `jsonReader: { repeatitems: false, root: function (obj) { return obj.Items[0].items; }, page: function (obj) { return obj.Items[0].page; }, total: function (obj) { return obj.Items[0].total; }, records: function (obj) { return obj.Items[0].records; } }` And I see my JSON at feedly and stay correct. – cavalsilva Jan 16 '14 at 14:38
  • @cavalsilva: I updated my answer. [The demo](http://www.ok-soft-gmbh.com/jqGrid/cavalsilva.htm) works. – Oleg Jan 16 '14 at 14:44
  • Thanks @Oleg, this problem is the `,` at last item the json. – cavalsilva Jan 16 '14 at 14:57