Skip to content

Commit 2cba433

Browse files
committed
#6529 grid.column.Component: support for function based components
1 parent e3fea17 commit 2cba433

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

examples/grid/bigData/GridContainer.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ class GridContainer extends BaseGridContainer {
5151
{type: 'index', dataField: 'id', text: '#', width: 60},
5252
{cellAlign: 'left', dataField: 'firstname', defaultSortDirection: 'ASC', text: 'Firstname', width: 150},
5353
{cellAlign: 'left', dataField: 'lastname', defaultSortDirection: 'ASC', text: 'Lastname', width: 150},
54-
{cellAlign: 'left', dataField: 'foo', text: 'Increase Counter', width: 130, component: {module: Button, text: 'Hello'}}
54+
{cellAlign: 'left', dataField: 'foo', text: 'Increase Counter', width: 150, component: ({record}) => ({
55+
module: Button,
56+
text : record.firstname + ' ++',
57+
width : 130
58+
})}
5559
];
5660

5761
for (; i <= value; i++) {

src/grid/column/Component.mjs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,31 @@ class Component extends Column {
4141
* @param {Number|String} data.value
4242
* @returns {*}
4343
*/
44-
cellRenderer({gridContainer, record, rowIndex}) {
45-
let me = this,
46-
{appName, view, windowId} = gridContainer,
47-
id = `${me.id}-component-${rowIndex % (view.availableRows + 2 * view.bufferRowRange)}`,
48-
component = me.map.get(id);
44+
cellRenderer(data) {
45+
let {gridContainer, record, rowIndex} = data,
46+
{appName, view, windowId} = gridContainer,
47+
me = this,
48+
id = `${me.id}-component-${rowIndex % (view.availableRows + 2 * view.bufferRowRange)}`,
49+
component = me.map.get(id),
50+
componentConfig = me.component;
51+
52+
if (Neo.typeOf(componentConfig) === 'Function') {
53+
componentConfig = componentConfig(data)
54+
}
55+
56+
console.log(componentConfig);
4957

5058
if (component) {
5159
component.set({
52-
record
60+
componentConfig
5361
})
5462
} else {
5563
component = Neo.create({
5664
appName,
5765
id,
5866
record,
5967
windowId,
60-
...me.component
68+
...componentConfig
6169
});
6270

6371
me.map.set(id, component)

0 commit comments

Comments
 (0)