Jqgrid, shows success in loading, but does not mount Grid

Asked

Viewed 316 times

2

I’m with a grid on my website I use the JqGrid. What is happening is that when the data comes back from the request, they are formatted the right way because the data itself JqGrid enters the method loadComplete, however, it does not load this data on the Grid.

Javascript do Jqgrid.

    $(document).ready(function () {
    $("#jqGrid").jqGrid({
        url: 'adm/controller/medico.php?acao=listarMedico',
        mtype: "POST",
        styleUI : 'Bootstrap',
        datatype: "json",
        colModel: [
            { label: 'id', name: 'idMedico', key: true, width: 75, hidden:true },
            { label: 'Nome', name: 'nomeMedico', width: 75 },
            { label: 'CRM', name: 'crmMedico', width: 150 },
            { label: 'Especialidades', name: 'especialidadesMedico', width: 150 },
            { label: 'Endereço', name: 'enderecoMedico', width: 150 },
            { label: 'Telefone', name: 'telefoneMedico', width: 150 }
        ],
        viewrecords: true,
        rowNum: 20,
        rowList: [20, 40, 100],
        //height: "auto",
        height: 400,
        emptyrecords: "Nenhum médico com o filtro selecionado",
        loadtext: "Buscando e carregando...",
        rowNum: 20,
        pager: "#jqGridPager",
        caption: "Médicos Conveniados",
        loadComplete: function(data){
            console.log('sucesso');
            console.log(data);
        },
        loadError: function (xhr,st,err) {
            console.log('HTTP status code: ' + xhr.status + '\n' +
                  'textStatus: ' + st + '\n' +
                  'errorThrown: ' + err);
            console.log('HTTP message body (jqXHR.responseText): ' + '\n' + xhr.responseText);
        }
    });
});

The return that PHP brings me and this in JSON:

{
  "total": 1,
  "page": 1,
  "records": 20,
  "rows": {
    "1": {
      "id": "1",
      "cell": {
        "idMedico": "1",
        "nomeMedico": "dsda",
        "crmMedico": "jknjk",
        "especialidadesMedico": null,
        "enderecoMedico": " ,  -  - ",
        "telefoneMedico": "() "
      }
    },
    "2": {
      "id": "2",
      "cell": {
        "idMedico": "2",
        "nomeMedico": "Henrique",
        "crmMedico": "CRM",
        "especialidadesMedico": null,
        "enderecoMedico": " ,  -  - ",
        "telefoneMedico": "() "
      }
    },
    "3": {
      "id": "3",
      "cell": {
        "idMedico": "3",
        "nomeMedico": "Henrique",
        "crmMedico": "CRM",
        "especialidadesMedico": null,
        "enderecoMedico": " ,  -  - ",
        "telefoneMedico": "() "
      }
    },
    "4": {
      "id": "4",
      "cell": {
        "idMedico": "4",
        "nomeMedico": "Henrique",
        "crmMedico": "CRM",
        "especialidadesMedico": null,
        "enderecoMedico": " ,  -  - ",
        "telefoneMedico": "() "
      }
    },
    "5": {
      "id": "5",
      "cell": {
        "idMedico": "5",
        "nomeMedico": "Henrique",
        "crmMedico": "CRM",
        "especialidadesMedico": null,
        "enderecoMedico": "Endere\u00e7o , Bairro - \u00c1gua Doce do Norte  - ES",
        "telefoneMedico": "() "
      }
    },
    "6": {
      "id": "5",
      "cell": {
        "idMedico": "5",
        "nomeMedico": "Henrique",
        "crmMedico": "CRM",
        "especialidadesMedico": null,
        "enderecoMedico": "Endere\u00e7o , Bairro - \u00c1gua Doce do Norte  - ES",
        "telefoneMedico": "() "
      }
    },
    "7": {
      "id": "5",
      "cell": {
        "idMedico": "5",
        "nomeMedico": "Henrique",
        "crmMedico": "CRM",
        "especialidadesMedico": null,
        "enderecoMedico": "Endereco , Bairro - Afonso Cl\u00e1udio - ES",
        "telefoneMedico": "() "
      }
    },
    "8": {
      "id": "5",
      "cell": {
        "idMedico": "5",
        "nomeMedico": "Henrique",
        "crmMedico": "CRM",
        "especialidadesMedico": null,
        "enderecoMedico": "Endereco , Bairro - Afonso Cl\u00e1udio - ES",
        "telefoneMedico": "() "
      }
    },
    "9": {
      "id": "6",
      "cell": {
        "idMedico": "6",
        "nomeMedico": "Henrique",
        "crmMedico": "CRM",
        "especialidadesMedico": null,
        "enderecoMedico": " ,  -  - ",
        "telefoneMedico": "() "
      }
    },
    "10": {
      "id": "7",
      "cell": {
        "idMedico": "7",
        "nomeMedico": "Henrique",
        "crmMedico": "CRM",
        "especialidadesMedico": null,
        "enderecoMedico": " ,  -  - ",
        "telefoneMedico": "() "
      }
    },
    "11": {
      "id": "8",
      "cell": {
        "idMedico": "8",
        "nomeMedico": "Henrique",
        "crmMedico": "CRM",
        "especialidadesMedico": null,
        "enderecoMedico": "Endere\u00e7o , Bairro - Afonso Cl\u00e1udio - ES",
        "telefoneMedico": "() "
      }
    },
    "12": {
      "id": "8",
      "cell": {
        "idMedico": "8",
        "nomeMedico": "Henrique",
        "crmMedico": "CRM",
        "especialidadesMedico": null,
        "enderecoMedico": "Endere\u00e7o , Bairro - Afonso Cl\u00e1udio - ES",
        "telefoneMedico": "() "
      }
    },
    "13": {
      "id": "9",
      "cell": {
        "idMedico": "9",
        "nomeMedico": "Henrique",
        "crmMedico": "CRM",
        "especialidadesMedico": null,
        "enderecoMedico": "Endere\u00e7o , Bairro - Afonso Cl\u00e1udio - ES",
        "telefoneMedico": "() "
      }
    },
    "14": {
      "id": "9",
      "cell": {
        "idMedico": "9",
        "nomeMedico": "Henrique",
        "crmMedico": "CRM",
        "especialidadesMedico": null,
        "enderecoMedico": "Endereco , Bairro - \u00c1gua Doce do Norte - ES",
        "telefoneMedico": "() "
      }
    },
    "15": {
      "id": "10",
      "cell": {
        "idMedico": "10",
        "nomeMedico": "Henrique",
        "crmMedico": "CRM",
        "especialidadesMedico": null,
        "enderecoMedico": "Endere\u00e7o , Bairro - Afonso Cl\u00e1udio - ES",
        "telefoneMedico": "(81) 98125-8886"
      }
    },
    "16": {
      "id": "10",
      "cell": {
        "idMedico": "10",
        "nomeMedico": "Henrique",
        "crmMedico": "CRM",
        "especialidadesMedico": null,
        "enderecoMedico": "Endereco , Bairro - \u00c1gua Doce do Norte - ES",
        "telefoneMedico": "() "
      }
    },
    "17": {
      "id": "11",
      "cell": {
        "idMedico": "11",
        "nomeMedico": "Henrique",
        "crmMedico": "CRM",
        "especialidadesMedico": null,
        "enderecoMedico": "Endere\u00e7o , Bairro - Afonso Cl\u00e1udio - ES",
        "telefoneMedico": "(81) 98200-5300"
      }
    },
    "18": {
      "id": "11",
      "cell": {
        "idMedico": "11",
        "nomeMedico": "Henrique",
        "crmMedico": "CRM",
        "especialidadesMedico": null,
        "enderecoMedico": "Endere\u00e7o , Bairro - Afonso Cl\u00e1udio - ES",
        "telefoneMedico": "(81) 98125-8886"
      }
    },
    "19": {
      "id": "11",
      "cell": {
        "idMedico": "11",
        "nomeMedico": "Henrique",
        "crmMedico": "CRM",
        "especialidadesMedico": null,
        "enderecoMedico": "Endereco , Bairro - \u00c1gua Doce do Norte - ES",
        "telefoneMedico": "() "
      }
    },
    "20": {
      "id": "12",
      "cell": {
        "idMedico": "12",
        "nomeMedico": "Henrique",
        "crmMedico": "CRM",
        "especialidadesMedico": null,
        "enderecoMedico": "Endere\u00e7o , Bairro - Afonso Cl\u00e1udio - ES",
        "telefoneMedico": "(81) 98200-5300"
      }
    }
  }
}

Would anyone know why Jqgrid isn’t mounting the data on the Grid?

1 answer

1

The problem has been solved. I asked that same question in stackoverflow, and the answer they gave me helped me solve the problem. In my JSON I did not mount Rows the way Jqgrid expects it to be in the Rows key to be that way:

[
    {"idMedico":"1",...},
    {"idMedico":"2",...},
    ...
    {"idMedico":"12",...}
]

To achieve this, in PHP I created the key rows in the array X, I rode a arrayseparated with the lines I wanted and gave a array_push passing the array X and specifying key rows.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.