PDA

View Full Version : Getting visible data from grid



nyga
24 Feb 2016, 1:46 PM
I'm looking for a solution to get rendered data from a grid. It means that I don't need to get data from store but the visible data from cells which users can see.


I get data as follows:

var data = [];
var i;
for (i = 0; i < store.data.length; i++) {
var row = grid.getView().getNode(i).innerText;
data.push(row.split("\n"));
}
but it doesn't seem elegant and it's easy to make a mistake.


Is there any other way to obtain the data?


Thanks in advance

jdkhamba
27 Feb 2016, 10:47 PM
Isn't the rendered data on the grid based on the data available in the store? So why not simply read the data from the store?

tristan.lee
14 Mar 2016, 11:59 PM
Is there a reason to not read from the store like mentioned above?

nyga
12 Apr 2016, 6:01 AM
Data from the store is not enough for me. Let's consider the simple example:
https://fiddle.sencha.com/#fiddle/18ih
Column 3 is sum of column 1 and column 2. Data which is displayed in col 3 is not from store directly (renderer adds values). So if I read only data form store, I don't receive data from col 3.

Any ideas?

jdkhamba
12 Apr 2016, 8:38 AM
You can simply make the data part of the model instead of the renderer:


Ext.define('testApp.model.Object', {
extend: 'Ext.data.Model',
fields: ['col1', 'col2', {
name: 'col3',
convert: function(v, rec) {
return rec.get('col1') + rec.get('col2');
}
}]
});


And have the column definition change to this:


columns: [{
text: 'Col A',
dataIndex: 'col1'
}, {
text: 'Col B',
dataIndex: 'col2'
}, {
text: 'A + B',
dataIndex: 'col3'


}]


Now you can easily access it from the store.See it in action:
https://fiddle.sencha.com/#fiddle/18j6