gridx shows the last record of my dynamic data

189 Views Asked by At

hello am using grid to display dynamic data dojo, but what I get is that sample (n) times, but always shows me the last record, but if I do it with dummy data works well, I hope you help me with this issue.

define(["js/module/modControllerPersona", "dojo/store/Memory", "gridx/Grid", "gridx/core/model/cache/Sync", "dojo/data/ObjectStore"], function(modControllerPersona, Store, Grid, Cache, ObjectStore){ var grid, store, data; var persona = new Array(); return{ datagridx: function(){ modControllerPersona.persona().then(function(result){ persona = JSON.parse(result); data = persona.items; store = new Store({data: data}); var columns = [ {name: 'id', field: 'descripcion'}, {name: 'descripcion', field: 'id_Maquinaria'}, {name: 'descripcion', field: 'id_tipo_Maquinaria'}, {name: 'Nombre', field: 'kind'}, {name: 'Nombre', field: 'nombre'}, {name: 'Nombre', field: 'visible'} ]; grid = new Grid({ cacheClass: Cache, store: store, structure:columns }, 'gridNode'); grid.startup(); });

2

There are 2 best solutions below

0
On

Perhaps this can help you, I had a similar problem. If you don't have a column id it doesn't work right. But if you adjust your store to something like this:

var store = new Memory({
    data:           data,
    idProperty:     'descripcion'
});

Perhaps the "new Memory" is not necassary. In my case this works (but I didn't tested it here again). I have no id but I have another unique field instead of this. I suppose it is because of your

{name: 'id', field: 'descripcion'}

If you use instead of "descripcion" the name "id" I think it should work too.

0
On

Just add "idProperty" for Gridx, I solved my problem

My dynamic data: var data = [{"ID":"1","Số liệu thống kê":"Năng suất lập trình","Ngôn ngữ LT":"Java Web","Công đoạn":"Code - Review Code","Loại Project":"Customize/Full","Đơn vị tính":"KLOC/ManMonth","UCD1":"11.6","ITS":null},{"ID":"2","Số liệu thống kê":"Năng suất lập trình","Ngôn ngữ LT":"Java Web","Công đoạn":"Code - Review Code - UT","Loại Project":"Customize/Full","Đơn vị tính":"KLOC/ManMonth","UCD1":"4.6","ITS":null},{"ID":"3","Số liệu thống kê":"Năng suất lập trình","Ngôn ngữ LT":"Java Web","Công đoạn":"Code","Loại Project":"Customize/Full","Đơn vị tính":"KLOC/ManMonth","UCD1":"15.15","ITS":null}];

require([ 'dojo/store/Memory', 'gridx/Grid', 'gridx/core/model/cache/Sync' ], function (Memory, Grid, Cache) { var store = new Memory({ data: data, idProperty: 'ID' }); Hope this help