Jgrid Retorna Json .NET
Boa tarde, preciso de um help,
Estou tentando executar uma Jgrid, retornando um serviço(.asmx), retorna do banco ok no Chrome porém não alimenta a grid e não da erro.
Segue:
aspx
<div id="dataTables_wrapper">
<table id="jQGridDemo">
</table>
<div id="jQGridDemoPager">
</div>
</div>
**asmx**
private relValidade relVal = new relValidade();
private HttpContext context;
JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
EntRelPrazoValidade entRelPrazoValidade = new EntRelPrazoValidade();
[WebMethod]
[scriptMethod(ResponseFormat = ResponseFormat.Json)]
public string HelloWorld()
{
DataTable dt = new DataTable();
dt = relVal.CarregaDados();
string json = string.Empty;
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
Dictionary<string, object> row;
foreach (System.Data.DataRow dr in dt.Rows){
row = new Dictionary<string, object>();
foreach (System.Data.DataColumn col in dt.Columns){
row.Add(col.ColumnName, dr[col]);
}
rows.Add(row);
}
json = jsSerializer.Serialize(rows);
return json;
}
**js**
$(document).ready(function () {
// debugger;jQuery("#jQGridDemo").jqGrid({
//type: "GET",
url: 'http://localhost:14365/Services/WebService.asmx/HelloWorld'
//data: "{}",
//crossDomain: false,
//cache: false,
contentType: "application/json; charset=utf-8",
serializeGridData: function (postData) {
return JSON.stringify(postData);
},method: "GET",
datatype: "json",
repeatitems: true,
key: true,
jsonReader: { repeatitems: true, root: "d.rows", page: "d.page", total: "d.total", records: "d.records" },
colNames: ['Cod Produto', 'Produto', 'Classe', 'Saldo'],
colModel: [
{ name: 'cdProduto', index: 'cdProduto', width: 120, stype: 'text' },
{ name: 'dsProduto', index: 'dsProduto', width: 180, stype: 'text' },
{ name: 'dsDescricaoClasse', index: 'dsDescricaoClasse', width: 180, stype: 'text' },
{ name: 'nrSaldo', index: 'nrSaldo', width: 100, stype: 'text' },
],
complete: function (jsondata, stat) {
if (stat == "success") {
var thegrid = jQuery("#liste")[0];
var datajson = JSON.parse(jsondata.responseText).d;
thegrid.addJSONData(datajson);
alert(datajson);
}else {
$(".loading").hide();
alert("Error with AJAX callback");
}
},
error: function (xmlHttpRequest, status, err) {//Caso ocorra algum erro:
$('.valor').html('Ocorreu um erro');
},
serializeGridData: function (postData) {
try {
return JSON.stringify(postData);
} catch (e) {
}
},
//success: function (data, status) { alert(data.d) },
//error: function (xmlHttpRequest, status, err) { alert("Erro") },rowNum: 10,
//mtype: 'GET',
loadonce: true,
rowList: [10, 20, 30],
sortname: 'cdProduto',
viewrecords: true,
//sortorder: "desc",
caption: "List Employee Details"
})
});
**Formato**
{"cdProduto":"EYA01445","dsProduto":"CARTÃO CIOC CLUB","dsDescricaoClasse":"DISPONIVEL","nrSaldo":6563}
Desde já, obrigado.
Discussão (0)
Carregando comentários...