Dynamic column in ListGrid

I need to add/remove columns in ListGrid dynamically per request based on user input.

For example, lets say if we have total A, B, C D columns. And ListGrid is displaying A,B by default and user select C and refresh the grid then it should display A,B,C columns.

What’s the best way to achieve it? I tried to do it with addDynamicDSGenerater API but it doesn’t seems to be working. Standalone code is attached. I will repost logs & screen shoot.

Reference: http://forums.smartclient.com/showthread.php?t=14742&page=3

Kindly advise.

Thanks,

BuiltInDS.html (1.88 KB)

BuiltInDS.java (1.88 KB)

MyDataSourceLoader.java (4.24 KB)

web.xml (5 KB)

Here are the server logs.

serverlog-part-1.txt (15.4 KB)

serverlog-part-2.txt (16.5 KB)

serverlog-part-3.txt (12.1 KB)

serverlog-part-4.txt (19.9 KB)

And here is the application screenshot.

screen-1.GIF

You need to use DataSource.load(“uniqueDSName”) in your client code.

But why not hide/show the fields?

@atomatom - Thanks for response.

We don’t have finite set for fields so we can have all and show/hide later. It all driven by user data.

DataSource.load(“uniqueDSName”) would have been my choice but the problem is - it doesn’t take DSrequest (or Criteria just to be more precise) as argument and i have to add/remove fields in data source definition based on user selection (or we can say per request).

Is it possible to send criteria as part of DataSource.load() request? If yes then it would do the trick for me.

If the criteria define the DataSource, there’s really no reason to work with the DataSourceLoader / dynamicDSGenerator system at all, which is designed around loading and pooling permanent DataSources.

Instead, define a DataSource with no fields, and in a DMI for that DataSource, use DataSource.fromXML() to create a second, temporary DataSource instance and use DataSource.execute() to execute the DSRequest. This temporary DataSource will then be garbage collected, which appears to be what you want.

It won’t work as Client still be looking into the datasource definition it has with no fields.

DMI creates the updated DataSource instance at serverside which fires executeFetch and gets the resultset nicely. This result set is also being sent to client but ListGrid only shows placeholder for records (you would know by turn on the row number field) and doesn’t show data/columns. I guess which makes sense as ListGrid is still looking to the datasource defination it has which contain no fields.

What I need is a way to update loaded datasource definition based on client criteria/request.

Reconsidering your stated use case, generating a server DataSource based on client-submitted criteria doesn’t really make sense - that’s just a gaping security hole. While you could achieve this by also dynamically providing fields to the grid based on the criteria, again, this seems like a nonsense scenario. If you think it’s a real scenario, please describe the actual UI you’re building in detail - not the APIs you think you need, but the end user experience and the purpose of the application.

Also, jumping back to your original post, there seems to be a static set of all possible columns that could be returned. If so, you don’t seem to need dynamic DataSources at all: just define a static DataSource with that set of columns, and show and hide fields in the grid based on the criteria if you want to hide data. To cut down on data being sent, you can also request just specific fields to be returned in the DSResponse via dsRequest.outputs.

The best use case example is the stand alone code what i have submitted with original post. Did you get a chance to run it locally?

This example has names of 3 columns (Name, Email, Salary) and a list grid. Now lets say user wants to include Email to grid for analysis - he would check the email column on UI and refresh the grid and email column should be part of grid. I thought it would be quite common scenario and that’s the reason i didn’t even try it during evaluation.

I will figure out some work around but given the impression i got working with SmartGWT API - I though there will be something very simple way to do this.

Kindly let me know if you have time and decide to look into standalone example.

Thanks for all your advices.

As explained below, the particular UI you’re showing with your sample code is best accomplished with just a static DataSource and does not require dynamic DataSources.

Code is not a use case. If you think you have a use case that isn’t being met by current APIs, what we need to discuss it further is a description of the end user experience and the purpose of the application.

Ya! that’s true. This stand alon example can be done with one static data source but it’s just a small POC. If we can get it working dynamically then anyone can enhance the example to add the functionality around.

We have already started the process to buy the licences. We can talk about the usecase through that channel. But meanwhile if you have any way to load modified data source definition at will then please let me know.

As an admirer of SmartGWT API - I would love to see an additional overloaded load method in client DataSource class with a definition like below.

DaatSource.load(String dsIds, Function callback, boolean forceReload, DSRequest properties)

Please have a little consideration, this will provide control to developer to deal with scenarios where someone has to drive datasource definition (with same ID or different ID earch time) from user request with no performance overhead.

Thanks,

For completeness, once again:

  • there is already the capability to load a dynamic DataSource by an ID
  • we have no use case that indicates that a method involving DSRequest Properties should be created - at the moment, it appears to fundamentally not make sense