0
votes

I have a problem loading data from JSON, when i assign the JSON to property "data" of JsGrid there are not data found in the table. I am retriving the data using Ajax.

$.ajax({
            url: '@Url.Action("consulta_Unidades")',
            async: false,
            type: 'POST',
            dataType: 'json',
            contentType: "application/json; charset=utf-8",
            success: function (response) {                   
                //console.log(response.value);
                datos = JSON.stringify(response);
                alert(datos);
            }
        });

The JsGrid code is next.

$("#table_div").jsGrid({

            width: "100%",
            height: "auto",

            editing: true,

            data: datos,

            fields: [
                { name: "id_almacen", type: "text", width: 150 },
                { name: "idunidad", type: "text", width: 150 },
                { name: "tipo_unidad", type: "text", width: 150 },
                { name: "nomenclatura ", type: "text", width: 150 },
                { name: "capacidad_tarimas", type: "text", width: 150 },
                { name: "altura", type: "text", width: 150 },
                { type: "control" }

            ]
        });

Any idea for resolve this problem?

1
Can you share what you see for alert(datos);? - Old Geezer
@Leonardo_Aguilar, we won't be able to help until we are sure about data format you are trying to set. So please provide us the result of alert(datos), as @Old_Geezer requested. - tabalin

1 Answers

1
votes

In your ajax success "response" its a json object, only check

if(response){
 datos=response
}

Another scenario:

The property "data" should be a "object" like json.

Change

datos = JSON.stringify(response);

For

datos = JSON.parse(response);

Use

datos = JSON.parse(JSON.stringify(response));

Only if it required for object "response"