0
votes

I am using smartgwt ( not the paid license version ) and I have a listgrid with three entries. Key, Value, Reset.

The reset-field is a button that should reset any changes to the value and here is where I struggle. I tried to implement it as simple as

@Override
public void onClick(ClickEvent event)
{
    DataSource ds = this.grid.getDataSource();
    ds.removeData(record);
    ds.fetchData();
    this.grid.redraw();
}

grid being my ListGrid and record the row that has been clicked to be reseted.

But this only removes the entry, it is there again if I reload ( even with the right value , because that is what my server does if he gets remove-requests), but I would like that it is there immediately after I click the button and not after clicking around a bit.

I assumed the fetchData and redraw request combined would accomplish this.

edit: Okay some more code, this shows my constructor for the ListGrid and the RevertButton which should remove and add the Record again.

    private static final String REVERT_NAME = "revertField";

    public MyListGrid(final String name)
    {
        this.setDataSource(PropertyListDS.getInstance(name);

        ListGridField keyField = new ListGridField(ConfigurationDataSourceFields.PROPERTY_NAME, "Property");
        ListGridField valueField = new ListGridField(ConfigurationDataSourceFields.PROPERTY_VALUE, "Value");
        ListGridField revertField = new ListGridField(REVERT_NAME, "Revert to Default");

        valueField.setCanEdit(true);

        this.setShowRecordComponents(true);        
        this.setShowRecordComponentsByCell(true);

        this.setAutoFetchData(true);

        this.setFields(keyField, valueField, revertField);
    }

    @Override
    protected Canvas createRecordComponent(final ListGridRecord record, Integer colNum)
    {
        String fieldName = this.getFieldName(colNum);
        Canvas canvas = null;
        if ( REVERT_NAME.equals(fieldName) ) 
        {
            canvas = new RevertButton(this, record);
        }
        return canvas;
    }

    private class RevertButton extends IButton implements ClickHandler
    {
        private final MyListGrid grid;
        private final ListGridRecord record;

        public RevertButton(final MyListGrid grid, final ListGridRecord record)
        {
            super();
            this.setTitle("Revert to Default");
            this.grid = grid;
            this.record = record;
            this.addClickHandler(this);
        }

        @Override
        public void onClick(ClickEvent event)
        {
            DataSource ds = this.grid.getDataSource();
            ds.removeData(record);
            ds.fetchData();
            this.grid.redraw();
        }
    }
1
so as per my understanding , remove from client-side works , but no changes at server side ? - Srinath Ganesh
It works on both ends, just not as I want it ;) The client doesn't see the change until he clicked a bit around in the ui is the problem. - user2329125
so you mean you got a time gap ? latency ? - Srinath Ganesh
Sort of yes, I wished the user would not even see that the record gets removed from the list and then added again with another value. But currently he sees that it gets removed and after he clicks around a bit the record is there again with the value it should have. It seems to me that ds.fetchData OR grid.redraw() are getting ignored. - user2329125
do post your GUI design for us to understand the exact working , what i feel will be a shortcut is, when user does reset(looks like record editing as per your Q) dont remove at client side , just edit the required places(textView.setText("new")) and let server update database . - Srinath Ganesh

1 Answers

2
votes

Do in this way using DSCallback.

DataSource#removeData() is a async call to the server. Either redraw the grid again or fetch the data again after getting response from server that record has been deleted in DSCallback.

DataSource dataSource = grid.getDataSource();
dataSource.removeData(record,new DSCallback() {

    @Override
    public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest){
        Record[] records=dsResponse.getData();//deleted records

        grid.fetchData();//fetch data again
    }
});

Please have a look at this thread Removing local record from listGrid without committing

Try with ListGrid#saveAllEdits() before fetching the data again.

You can try with ListGrid#removeSelectedData() to remove the currently selected records from this component. If this is a databound grid, the records will be removed directly from the DataSource.