Configuring ListGrid selection in SmartGWT

I am trying to set the selected records of a ListGrid table object in SmartGWT, but I cannot find a way to do this. I know that there is a getSelectedRecords () function, but there are no corresponding setSelectedRecords (). I tried to check if set / getSelectedState () would work, but GWT complains about the need to use a primary key and a DataSource object. Is there any way to set the selection of ListGrid?

+4
source share
1 answer

To do this, you can use one of the selectRecords() methods, for example:

 public void onModuleLoad() { VLayout main = new VLayout(); final ListGrid grid = new ListGrid(); grid.setHeight(500); grid.setWidth(400); grid.setFields(new ListGridField("name", "Name")); grid.setData(createRecords()); final IButton button = new IButton("Select some"); button.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { grid.selectRecords(new int[]{2, 3}); //This will select index 2 and 3 } }); main.addMember(grid); main.addMember(button); RootPanel.get().add(main); } private ListGridRecord[] createRecords() { return new ListGridRecord[]{ createRecord("monkey"), createRecord("banana"), createRecord("orange"), createRecord("sun") }; } private ListGridRecord createRecord(String name) { ListGridRecord record = new ListGridRecord(); record.setAttribute("name", name); return record; } 
+4
source

Source: https://habr.com/ru/post/1342494/


All Articles