user173342
user173342

Reputation: 1840

Slickgrid not displaying JSON data from PHP unless I edit cells

As the title says, I have slickgrid getting/parsing JSON data from PHP, but while I can get it to update to the proper row count, nothing is displayed in a cell unless I edit it first. When I do, the correct data is displayed, but only for cells I have edited. Here is the relevant code:

$(function () {
 $.getJSON("./test3.php", function(jsondata) {
  $.each(jsondata, function(i, arr) {
   var d = (data[i] = {});
   $.each(arr, function(key, value) {
    d[key] = value;
   });
  });

  grid.updateRowCount();
  grid.render();
 });

grid = new Slick.Grid("#myGrid", data, columns, options);

//continues function prepping the grid

Upvotes: 0

Views: 2251

Answers (2)

user173342
user173342

Reputation: 1840

I needed to call grid.invalidateRow() on all of the added rows.

Upvotes: 0

ghiscoding
ghiscoding

Reputation: 13194

You might want to go for simpler implementation, there's no need to loop through all your data just dump your "jsondata" directly inside the SlickGrid Object creation. As long as you have the "data" array into a JSON Object then you're fine. Something like this:

{ "data":[{"id":"84","name" : "Someone" ... ]}
// then pass it to your Slick Object.
grid = new Slick.Grid("#myGrid", jsondata, columns, options);

That's all... Oh and don't forget to have at least have a unique "id" on all rows

You can see example from this web site: http://joeriks.com/2011/07/03/a-first-look-at-slickgrid-with-read-and-update-in-webmatrix/

Upvotes: 1

Related Questions