jquery-bootgrid
jquery-bootgrid copied to clipboard
Uncaught TypeError: Cannot read property 'length' of undefined
I have the following error when trying to run my bootgrid:
Uncaught TypeError: Cannot read property 'length' of undefined at Grid.renderRows (jquery.bootgrid.js:585) at update (jquery.bootgrid.js:200) at Object.success (jquery.bootgrid.js:238) at fire (jquery-3.1.1.js:3305) at Object.fireWith [as resolveWith] (jquery-3.1.1.js:3435) at done (jquery-3.1.1.js:9242) at XMLHttpRequest.
(jquery-3.1.1.js:9484)
I have implemented my bootgrid as follows:
var grid = $("#ContactsTbl").bootgrid({
ajax: true,
ajaxSettings: {
method: "GET",
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false
},
url: "/Contacts/IndexJson",
rowCount: [10, 50, 75, 100, 200, -1]
}).on("loaded.rs.jquery.bootgrid", function (e) {
$("#ContactsTbl").removeClass("hidden");
});
Any idea what would be causing this? :/
Well i am facing the same issue right now. Any help ?
@barrydoyle18 @niranthreddy I am having the same issue. Have you guys find the problem yet?
have you tried setting a breakpoint in dev tools and have a look at the structure of the response to the ajax call?
anyone figure this out? My json response looks fine to me but im still hitting this error :(
Could you post the json response? Anytime I get this issue, the problem turns out to be a miss formed json response. As you know, by default the plugin expects the response object to contain (among other attributes) rows: { rows: [ { id: 1, name: 'Bla'}, { id: 1, name: 'Bla2'},....]}. So, even if your response contains 'rows', make sure its an array. Even if it's an empty array.
Solution is to add strings at the beginning and the end of json results.
The response's format expect plugin like @ksidibe says:
{ "current": 1, "rowCount": 10, "rows": [ { "id": 19, "sender": "[email protected]", "received": "2014-05-30T22:15:00" }, { "id": 14, "sender": "[email protected]", "received": "2014-05-30T20:15:00" }, ... ], "total": 1123 }
The format of a JSON obtained vía json_encode PHP function (i'm converting a laravel object)
[ { "id": 19, "sender": "[email protected]", "received": "2014-05-30T22:15:00" }, { "id": 14, "sender": "[email protected]", "received": "2014-05-30T20:15:00" }, ... ]
As can you see, json don't have the begging and the end of response plugin expect.
Then i solved that adding a few string like this
return ('{"rowCount": 10,"rows":'. json_encode($myqueryobject).',"total": 1123}');
$myqueryobject is the query i made using laravel eloquent in my case 10 and 1123 can be replaced getting the data of a query.
hope it helps.
regards