javascript - Populate grid with row/column coordinates in extjs -
i'm trying populate extjs grid data json. values need populate in cells in object gives row , column number. i'm not sure how values correct cells json structure.
here json:
{ "_links" : { "self" : { "href" : "http://localhost:8080/api/reports" } }, "columns" : [ { "softwarebuild" : { "buildid" : 10, "generation" : "alpha", "build" : "1.0" }, "eventtypedisplay" : "event name 1" }, { "softwarebuild" : { "buildid" : 10, "generation" : "beta", "build" : "2.0" }, "eventtypedisplay" : "event name 1" }], "entries" : [ { "row" : 0, "column" : 0, "value" : 10 }, { "row" : 0, "column" : 1, "value" : 20 }, { "row" : 1, "column" : 0, "value" : 30 }, { "row" : 1, "column" : 1, "value" : 40 } ], "rows" : [ { "metrictypeid" : 1, "metricname" : "name 1", "source" : "1", }, { "metrictypeid" : 2, "metricname" : "name 2", "source" : "2", }] }
here grid view:
ext.create('ext.grid.panel', { renderto: document.body, store: 'datastore', width: 400, height: 200, title: 'software metrics', columns: [ { text: 'dynamic column name', dataindex: '' } ] });
here model , store:
ext.define('datamodel', { extend: 'ext.data.model', fields: [ 'value', 'generation', 'build', 'metricname', 'source' ] }); ext.define('datastore', { extend: 'ext.data.store' model: 'datamodel', proxy: { type: 'rest', url : 'api/reports' } });
another question have how populate column headers "build" value columns array in json object. , how populate cells in first column "metricname" rows array. question.
this process take time i'll tell need do:
1 - json structure , assign variable, should use ext.ajax.request this.
2 - loop through columns object , create object valid column format extjs like:
var columns = [{ text : '1.0', dataindex: 'alpha' },{ text: '2.0', dataindex : 'beta' }];
3 - apply columns grid using grid.reconfigure(columns);
4 - model should have fields : ['alpha', 'beta']
5 - store should use memory proxy since grabbed data using ext.ajax.request.
6 - loop through entries object , total number of rows should added.
var entries = [{ "row" : 0, "column" : 0, "value" : 10 }, { "row" : 0, "column" : 1, "value" : 20 }, { "row" : 1, "column" : 0, "value" : 30 }, { "row" : 1, "column" : 1, "value" : 40 }]; var rows = []; (var i=0;i<entries.length;i++) { var currentrow = entries[i].row, currentcolumn = entries[i].column, columnname = columns[currentcolumn].dataindex; if(currentrow > rows.length - 1) { rows.length = currentrow + 1; } if (!rows[currentrow]) rows[currentrow] = {}; rows[currentrow][columnname] = entries[i].value; }
7 - add assign rows value store using store.loadrawdata
Comments
Post a Comment