Announcement

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

    ListGrid - Remove row using row icon

    I am using a ListGrid with records that are not datasource bound. I would like to add a delete-icon to every row of the grid. I think that I should be able to do this by using the
    Code:
    grid.setCanRemoveRecords(true);
    .

    This seems to add the icon to my grid, but I am not capable of figuring out which listener to add to the grid in order to react to the delete icon clicking. Do I have to use the
    Code:
    grid.addCellClickHandler(CellClickHandler);
    and then figure out if the icon was clicked?


    Help would be much appreciated.

    #2
    In another thread I found another solution to my problem. This solution does not involve using the "canRemoveRecords" attribute.

    Originally posted by alius
    Hi,
    Instead of using listGrid.setCanRemoveRecords(true) you have to manually create "remove" field:
    Code:
    ListGridField removeField = new ListGridField ("removeAction", 20);
    removeField.setType (ListGridFieldType.ICON);
    removeField.setCellIcon (SkinPreLoader.getSkinDir () + "images/actions/remove.png");
    removeField.setCanEdit (false);
    removeField.setCanFilter (true);
    removeField.setFilterEditorType (new SpacerItem ());
    removeField.setCanGroupBy (false);
    removeField.setCanSort (false);
    removeField.addRecordClickHandler (new RecordClickHandler () {
        public void onRecordClick (final RecordClickEvent event) {
            SC.confirm ("Remove?", "Do you really want to remove selected row?", new BooleanCallback () {
                public void execute (Boolean value) {
                    if (Boolean.TRUE.equals (value)) {
                        listGrid.removeData (event.getRecord ());
                    }
                }
            });
        }
    });
    Add this field to list grid along other fields.

    Alius.

    Comment


      #3
      Thanks. This helped me. In my case, I'm using a listgrid with a datasource, but the remove doesn't visually get rid of the record. I have to invalidate the cache, but the setCanRemoveRecords(true) doesn't pass the component id of the grid in the request, so there's no way of getting the grid and invalidating the cache. Hopefully this will work, though. It's counter-intuitive and not worth even using these built-in functionalities if they are useless though.

      Comment


        #4
        See the FAQ about grids not updating. You do not need to invalidate the cache (and should not).

        Comment


          #5
          It helped me as well but I am facing one new problem.

          With this approach, when I remove the last record I expect an empty grid. But what i get is an a new record with empty values. I dont need this new editing record.

          How can I disable this?

          Comment

          Working...
          X