Search code examples
datagridsmartgwt

In SmartGWT, do hidden columns have to be returned in the fetch of a datagrid's records?


I am a recent addition to a Dev team that uses Smart GWT and have very little experience with the library. We have several datagrids in the application that offer a large number of columns (up to 80) however, most of these columns are set to hidden by default. Apparently, SmartGWT requests all columns in each call to the database (initial load, paging, etc), even though the majority of the data is not shown to the user. I understand the logic here is to allow for fast updates when a user chooses to show a previously hidden column using the "Column Chooser" context menu option, but in the case of these grids I would much prefer to re-select the data with the now shown column then bear the cost of each load with data that is likely not being displayed. Any recommendations?


Solution

  • Please have a look at DataSource#setDropExtraFields()

    Use DSRequest#setOutputs() to fetch a selected columns from database.

    Sample code:

    StringBuilder outputs=new StringBuilder();
    for (ListGridField field : grid.getFields()) {
        if (grid.fieldIsVisible(field.getName())) {
            outputs.append(",").append(field.getName());
        }
    }
    DSRequest dsRequest=new DSRequest();
    dsRequest.setOutputs(outputs.substring(1));
    
    grid.fetchData(new Criteria(), new DSCallback() {
        
        @Override
        public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) {
            ...
        }
    }, dsRequest);