Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    ListGrid - hold the remove from database, until Save button is clicked

    Hi,

    I am using SmartGWT 2.5 Pro.

    As mention in the title, I would like to onhold the record remove from the database until the user manually click on the Save button that I implemented. When user hit on the "delete" key, I want to remember that the selected record is to be delete. To do this, I set the following in the ListGrid. Also, I added the KeyPressHandler.

    1. setCanRemoveRecords -> false
    2. setAutoSaveEdits -> false

    However, the record will be deleted from database, when user hit on the "delete" button. How can I disable it and just set the record state to delete (not sure this is doable)?

    It is working for edit and add new record.


    Sample code as following:
    final ListGrid userList = new ListGrid();
    userList.setWidth(600);
    userList.setHeight(224);
    userList.setDataSource(customDS);
    userList.setCanEdit(true);
    userList.setCanRemoveRecords(false);
    userList.setAutoSaveEdits(false);
    userList.setLeaveScrollbarGap(false);
    userList.setDataFetchMode(FetchMode.LOCAL);
    userList.setAutoFetchData(true);

    userList.setFields(
    new ListGridField("userName"),
    new ListGridField("job"),
    new ListGridField("email"),
    new ListGridField("employeeType"),
    new ListGridField("salary")
    );

    userList.addKeyPressHandler(new KeyPressHandler(){

    @Override
    public void onKeyPress(KeyPressEvent event) {
    if(event.getKeyName().equals("Delete")){

    userList.removeData(userList.getRecord(userList.getEventRow()));
    }
    }
    });


    Appreciate your help.

    #2
    It is going to delete because you have the grid bound to the data source and then you call a delete on it. setCanRemoveRecords doesnt actually tell the listGrid it cant delete, it just won't display the built in delete button. A delete is also not considered an edit, so autoSaveEdits will not help you here.

    Instead of calling:
    Code:
    userList.removeData(userList.getRecord(userList.getEventRow()));
    You might want to try getting the records from your dataSource directly:

    Code:
    DataSource.get("dSName").fetchData(new Criteria("....", ....), new DSCallback() {
    
    			@Override
    			public void execute(DSResponse response, Object rawData, DSRequest request) {
    				getView().listGrid().setData(response.getData());
    			}
    		});
    This way the list will have the data but can not manipulate your database. You will have to manually add the save function as far as I know (this is how I do it) but this also allows you to keep track of deletes and to delete only when they hit save or not to if they cancel.

    Comment


      #3
      Try using markRecordRemoved instead of removeData.

      Comment


        #4
        That's a 3.0 API by the way.

        Comment


          #5
          Oops, sorry about that. I just happened to run across that function while looking for something else. But yes, I'm using 3.0.

          Comment

          Working...
          X