Dynamically Adding Fields to DataSource

SmartGWT 2.5 on Chrome

I am trying to dynamically add fields and their corresponding value maps to a DataSource. I’ve gotten this DataSource via an XML definition and calling DataSource.get(). When I try to add fields after calling .get(), I receive an error saying that I cannot modify the component after it has been created.

I have no way of knowing which columns I’m going to get back from the database, so I have no way of creating a mapping prior to execution. I do however know what my CRUD operations will look like (we have a middle tier with stored procedures). The custom data source model that we’re using seems to give us all the functionality we need aside from adding custom DataSourceFields with corresponding value maps.

How might I do this?

If you are doing the database fetches yourself (not using SQLDataSource to generate the SQL), then you may want to simply declare a DataSource with no fields, then provide a set of dynamically generated fields to the ListGrid that will show the results. Note DataSource.dropExtraFields - set this to false to avoid data being trimmed off.

If instead you are trying to have SQLDataSource adapt to a dynamically changing DB table, you can do this by generating a DataSource dynamically - see DataSource.addDynamicDSGenerator.