yorl1n / ext.ExportableGrid

Wrapper over ExtJs's grid to make grid exportable.
MIT License
13 stars 7 forks source link

Take cell type from grid column type instead of model field type. #4

Closed nbgo closed 8 years ago

nbgo commented 8 years ago

https://s3.amazonaws.com/donnicky_screenshots/2016-03-04_02-34-39_a092e528-324c-4ea1-a5cd-dfa4f6691f88.png

As far as Ext JS 5 (and 6 as well) allows to bypass fields definition on models then logic from screenshot will almost always produce cells of default type. It would be nicer to define cell type from grid column type, because it is always declared explicitly.

yorl1n commented 8 years ago

Thanks for report. I'll take a look

yorl1n commented 8 years ago

Could you please specify what do you mean by column type ? If you mean xtype, then it will be difficult to do this while custom xtypes could be used. And it is a bad practice not to provide field types, while the same field can contain mixed values, that's why default string is used in my case.

nbgo commented 8 years ago

@yorl1n not xtype, because it can be really be any. Now I check via instanceof so if it is custom it will be inherited from one of base types anyway.

getExportableColumnType: function (gridColumn) {
    if (Ext.grid.column.Number && gridColumn instanceof Ext.grid.column.Number) {
        return this.columnTypes['float'];
    }
    if (Ext.grid.column.Date && gridColumn instanceof Ext.grid.column.Date) {
        return this.columnTypes['date'];
    }
    if (Ext.grid.column.Boolean && gridColumn instanceof Ext.grid.column.Boolean) {
        return this.columnTypes['boolean'];
    }
    if (Ext.grid.column.Check && gridColumn instanceof Ext.grid.column.Check) {
        return this.columnTypes['boolean'];
    }
    return this.defaultType;
},
yorl1n commented 8 years ago

@nbgo It depends on approaches. F.e. in our project due to specific data and some inconvenient behavior of Column component we use override of the parent Column class with renderers(number, date etc.), it gives more flexibility and prevents overriding of every Column subtype. But for cases where appropriate column type is used your solution will be better.

P.S. The approach that you provide is exactly the xtype. At least I meant using of column classes(generally provided by xtype to use lazzy flavors) for value type detection in my question.

nbgo commented 8 years ago

Perhaps it could be an option how to detect exportable column type....

yorl1n commented 8 years ago

Yeah, thanks. Upd: removed erroneous assumption.

yorl1n commented 8 years ago

Added your improvement into readme

nbgo commented 8 years ago

Thank, you.