SmartGWT: How to make ListGrid respond to datasource structure chages after adding, updating, removing operatios?

183 views Asked by At

I have a dynamic DataSource and it is bound to a ListGrid. By dynamic understand that its columns depending on data in a database.

So, after insert, update, or remove a line in my ListGrid the datasource structure may change. Then I need to reload the datasource in order to verify if its structure (columns) should be changed. Ergo, the ListGrid must respond to these eventual changes.

For instance, when a new line is added to the database table and consequently listed in the ListGrid, maybe a new column could be displayed toward showing the entire data for that line. If this line is removed, then that new column must be removed.

The problem is that after inserting or removing, even if I call the method responsible of reloading the datasource and destroying and recreating the grid, the columns stay the same. Please, take a look at my code below:

Method for loading the datasource:

private void generateNumberRangesDataSourceDynamycally() {

    String appID = AppServiceConstants.APP_ID;
    String className = AppServiceConstants.SCAFACADE_SERVICE_NAME;
    String methodName = AppServiceConstants.METHOD_GETNUMBERRANGES;

    DMI.call(appID, className, methodName, new PAIRPCCallback() {

        @Override
        public void executeRPCCall(RPCResponse response, Object rawData, RPCRequest request) {

            if (response.getStatus() == RPCResponse.STATUS_FAILURE) {

                SC.warn( scatext.error_numberrange_datasource_generation() );

            }

        }

    }, loadNumberRangesDataSource());

}

Trigger method that starts the DMI for dynamically loading the datasource:

private Object[] loadNumberRangesDataSource() {

    DataSource.load(LUNummernkreiseContent.DYNAMICDS_ID, dataSourceCallbackFunction(), true);

    return new Object[] { AppController.getRequestToken() };

}

Callback function for dynamic datasource loading:

private Function dataSourceCallbackFunction() {

    final Function function = new Function() {

        @Override
        public void execute() {

            display.getLayout().getGrid().destroy(); // destroying the HTML reference to the component;
            display.getLayout().setGrid( null ); // nullifying the java object

            dsDynamic = DataSource.get( LUNummernkreiseContent.DYNAMICDS_ID );

            if (dsDynamic != null) {

                setupGrid();
                refreshGrid();


            }
        }

    };

    return function;
}

Following methods are responsible for setting up the grid and fetching current data:

protected void refreshGrid() {

    display.getLayout().getGrid().fetchData( criteria );

}

protected void setupGrid() {

    display.getLayout().getGrid().setDataSource( dsDynamic );

    final HeaderSpan headerSpan = new HeaderSpan(scatext.screen_lunummernkreis_grid_luHeaderSpan(),
            new String[] {LUNummernkreiseContent.START_FIELD, LUNummernkreiseContent.END_FIELD});

    display.getLayout().getGrid().setHeaderSpans( headerSpan );
    display.getLayout().getGrid().getField( LUNummernkreiseContent.START_FIELD ).setTitle( scatext.screen_lunummernkreis_window_spinnerFrom() );
    display.getLayout().getGrid().getField( LUNummernkreiseContent.END_FIELD ).setTitle( scatext.screen_lunummernkreis_window_spinnerTo() );
    display.getLayout().getGrid().getField( LUNummernkreiseContent.DELIVERYTYPE_FIELD ).setTitle( scatext.screen_lunummernkreis_window_comboType() );
    display.getLayout().getGrid().getField( LUNummernkreiseContent.COUNTRYNAME_FIELD ).setTitle( scatext.screen_lunummernkreis_window_comboCountry() );
    display.getLayout().getGrid().getField( LUNummernkreiseContent.COUNTRYCODE_FIELD ).setTitle( scatext.screen_lunummernkreis_grid_columnCountryCode() );

}

Any idea? Emphasizing the point: I need that the grid responds to dynamic structural datasource changes, after performing CRUD operation.

0

There are 0 answers