Announcement

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

    Selecting several records after deleting from the grid

    I want to give the user the ability to quickly delete selected records. I want the next record to be automatically selected after deleting previous. It would be nice to be able to select several records at once and delete them as well.

    In this scenario I get an error:

    "Some records in the range you selected are not loaded. Scroll through the entire range before selecting it."

    1. Select first record ("Pat")
    2. Click [remove] button
    3. Click "Joe" with shift

    If I select these two records again, it works.


    SmartGWT 13.1d 2024-02-06
    macOS 13.2.1
    Chrome 121.0.6167.139 , Safari 16.3


    Code:
            RecordList rl = new RecordList();
    
            rl.add(createTestRecord(1, "Pat", "Smith"));
            rl.add(createTestRecord(2, "Sue", "Nowak"));
            rl.add(createTestRecord(3, "Joe", "Brown"));
            rl.add(createTestRecord(4, "Leo", "White"));
            rl.add(createTestRecord(5, "Teo", "McDonald"));
    
            DataSource ds = new DataSource();
            ds.setClientOnly(true);
            DataSourceIntegerField f1 = new DataSourceIntegerField("id");
            f1.setPrimaryKey(true);
            DataSourceTextField f2 = new DataSourceTextField("name");
            DataSourceTextField f3 = new DataSourceTextField("surname");
    
            ds.setFields(f1, f2, f3);
            ds.setCacheData(rl.toArray());
    
            VLayout vl = new VLayout();
    
            ListGrid testGrid = new ListGrid();
            testGrid.setDataSource(ds);
            testGrid.setAutoFetchData(false);
            testGrid.setShowAllRecords(true);
    
            testGrid.fetchData();
    
            Button removeButton = new Button("remove");
            removeButton.addClickHandler(new ClickHandler() {
                final ListGrid grid = testGrid;
                @Override
                public void onClick(ClickEvent event) {
                    Record r = grid.getSelectedRecord();
                    grid.removeSelectedData(new DSCallback() {
                        final int recordIndex = grid.getRecordIndex(r);
                        @Override
                        public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) {
                            grid.selectSingleRecord(recordIndex);
                        }});
                }
            });
    
            vl.addMembers(testGrid,removeButton);
    Code:
    private Record createTestRecord(int id, String name, String surname) {
            Record r = new Record();
            r.setAttribute("id", id);
            r.setAttribute("name", name);
            r.setAttribute("surname", surname);
            return r;
        }
    Click image for larger version

Name:	Zrzut ekranu 2024-02-8 o 14.12.59.png
Views:	194
Size:	27.2 KB
ID:	271630
    Click image for larger version

Name:	Zrzut ekranu 2024-02-8 o 14.13.10.png
Views:	167
Size:	27.3 KB
ID:	271631
    Click image for larger version

Name:	Zrzut ekranu 2024-02-8 o 14.13.23.png
Views:	149
Size:	55.3 KB
ID:	271632
Working...
X