mleibman / SlickGrid

A lightning fast JavaScript grid/spreadsheet
http://wiki.github.com/mleibman/SlickGrid
MIT License
6.81k stars 1.98k forks source link

Uncaught Each data element must implement a unique 'id' property #990

Open ghost opened 10 years ago

ghost commented 10 years ago

When I bind json data to slick using dataview it shows above error what is the problem here can any one help me

6pac commented 10 years ago

Did you look at the source of the examples ? Your JSON must have an 'id' property, as the error says. It's not hard. But you'd need to post a sample of your data here to get any assistance at all.

ghost commented 10 years ago

Here is my json sample [{ "empid": 1, "fname": "John", "lname": "Doe", "email": "jdoe@gmail.com", "sdate": "4/3/2012" }, { "empid": 2, "fname": "Stuart", "lname": "Motzart", "email": "jdoe@gmail.com", "sdate": "4/3/2012" },]

ghost commented 10 years ago

Thanks for giving the reply and the thing is if Iam using ajax call directly it displays nicely with same service url

ldmberman commented 10 years ago

Just rename "empid" into "id" and it will work. It is what "must implement a unique 'id' property" means.

On Thu, Aug 21, 2014 at 4:15 PM, LavanyaJujjavarapu < notifications@github.com> wrote:

Here is my json sample [{ "empid": 1, "fname": "John", "lname": "Doe", "email": "jdoe@gmail.com", "sdate": "4/3/2012" }, { "empid": 2, "fname": "Stuart", "lname": "Motzart", "email": " jdoe@gmail.com", "sdate": "4/3/2012" },]

— Reply to this email directly or view it on GitHub https://github.com/mleibman/SlickGrid/issues/990#issuecomment-52911637.

ghost commented 10 years ago

great it works but grid is displaying data is not populated

ghost commented 10 years ago

this is my code what's the problem here and onrowschanged and onrowscountchanged functions are nott fired dataView = Slick.Data.DataView(); dataView.beginUpdate(); dataView.setItems(obj); dataView.endUpdate();

                         grid = new Slick.Grid("#teamGrid", dataView, columns, options);
                       dataView.onRowsChanged.subscribe(function (e, args) {
                             grid.invalidateRows(args.rows);
                             grid.render();
                         });
                         dataView.onRowCountChanged.subscribe(function (e, args) {
                             grid.updateRowCount();
                             grid.render();
                         });
ldmberman commented 10 years ago

Firstly, try to compare your code to one of the examples in repository. If still nothing seems wrong, make a jsfiddle http://jsfiddle.net/ example - it would be much easier to help you after that.

On Thu, Aug 21, 2014 at 4:36 PM, LavanyaJujjavarapu < notifications@github.com> wrote:

this is my code what's the problem here and onrowschanged and onrowscountchanged functions are nott fired dataView = Slick.Data.DataView(); dataView.beginUpdate(); dataView.setItems(obj); dataView.endUpdate();

                     grid = new Slick.Grid("#teamGrid", dataView, columns, options);
                   dataView.onRowsChanged.subscribe(function (e, args) {
                         grid.invalidateRows(args.rows);
                         grid.render();
                     });
                     dataView.onRowCountChanged.subscribe(function (e, args) {
                         grid.updateRowCount();
                         grid.render();
                     });

— Reply to this email directly or view it on GitHub https://github.com/mleibman/SlickGrid/issues/990#issuecomment-52913520.

amanmahajan7 commented 10 years ago

You do not need to rename empid to id. When you set the items in setItems function, you can specify the id property.

setItems(items, "empid")

This is the definition of setItems function.

function setItems(data, objectIdProperty) {
  if (objectIdProperty !== undefined) {
    idProperty = objectIdProperty;
  }
  items = filteredItems = data;
  idxById = {};
  updateIdxById();
  ensureIdUniqueness();
  refresh();
}

On Aug 21, 2014, at 7:18 AM, ldmberman notifications@github.com wrote:

Just rename "empid" into "id" and it will work. It is what "must implement a unique 'id' property" means.

On Thu, Aug 21, 2014 at 4:15 PM, LavanyaJujjavarapu < notifications@github.com> wrote:

Here is my json sample [{ "empid": 1, "fname": "John", "lname": "Doe", "email": "jdoe@gmail.com", "sdate": "4/3/2012" }, { "empid": 2, "fname": "Stuart", "lname": "Motzart", "email": " jdoe@gmail.com", "sdate": "4/3/2012" },]

— Reply to this email directly or view it on GitHub https://github.com/mleibman/SlickGrid/issues/990#issuecomment-52911637.

— Reply to this email directly or view it on GitHub.

ghost commented 10 years ago

If these two functions are not executing means problem with json data?

ghost commented 10 years ago

dataView.onRowCountChanged.subscribe(function (e, args) { grid.updateRowCount(); alert("hi"); grid.render(); });

dataView.onRowsChanged.subscribe(function (e, args) { grid.invalidateRows(args.rows); alert("bye"); grid.render(); });