Announcement

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

    ListGrid disabled record remove

    Hi,

    I use setRecordEnabledProperty on ListGrid to disable some records.
    I also use setCanRemoveRecords on ListGrid.
    I expect, when the record is disabled, the remove icon should be disabled too - but it's not. Why ?

    smartgwt pro 3.0 latest NB

    thank you.

    #2
    It could be argued either way how this combination of settings *should* behave (is deleting the record an action on the record or on the set of records?) but if you would like disabled rows to be unable to be deleted, you should add your own field for deleting records: a field of type "icon" where the CellClickEvent handler calls removeData().

    Comment


      #3
      Hi, I have the same problem and did as you suggested.

      Code:
      listGrid.setRecordEnabledProperty("canEdit");
      
      ListGridField removeField = new ListGridField("removeAction", 20);
      removeField.setType(ListGridFieldType.ICON);
      removeField.setCellIcon("[SKIN]/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) {
      		listGrid.removeData(event.getRecord());
      	}
      });
      I want the icon in the disabled rows to be greyed out, and I was hoping that it would automatically put the "_Disabled" suffix on the icon url, but it didn't.

      How would I go about setting the icon url for each record individually based on the "canEdit" attribute?

      Any help would be much appreciated.

      /Futtegud

      Comment


        #4
        I managed to solve this using valueIcons. I'm not sure if this is the supposed/best method of doing this but it works.

        Code:
        LinkedHashMap<String, String> valueIcons = new LinkedHashMap<String, String>();
        valueIcons.put("Enabled", "[SKIN]../actions/remove.png");
        valueIcons.put("Disabled", "[SKIN]../actions/remove_Disabled.png");
        
        ListGridField removeField = new ListGridField("removeAction","", 20);
        removeField.setType(ListGridFieldType.ICON);
        removeField.setValueIcons(valueIcons);
        //removeField.setIcon("[SKIN]/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.ask("Are you sure you want to delete these reported hours?", new BooleanCallback() {
        			@Override
        			public void execute(Boolean value) {
        				if(value)
        					listGrid.removeData(event.getRecord());
        			}
        		});
        	}
        });
        The server then returns "Enabled" or "Disabled" depending on whether or not the row is disabled.

        For future reference a ListGridFieldType.STATEFUL_ICON would be very useful.

        /Futtegud

        Comment

        Working...
        X