2016-06-25 2 views
0

데이터 격자 표에서 선택한 모든 행을 가져 오는 방법이 필요합니다. 여기 내 코드는 다음과 같습니다.GWT Datagrid에서 선택한 모든 행의 값을 가져 오는 방법은 무엇입니까?

import java.util.Arrays; 
import java.util.List; 

import com.google.gwt.core.client.EntryPoint; 
import com.google.gwt.user.cellview.client.DataGrid; 
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy; 
import com.google.gwt.user.cellview.client.TextColumn; 
import com.google.gwt.user.client.Window; 
import com.google.gwt.user.client.ui.RootLayoutPanel; 
import com.google.gwt.user.client.ui.SimpleLayoutPanel; 
import com.google.gwt.view.client.MultiSelectionModel; 
import com.google.gwt.view.client.SelectionChangeEvent; 
import com.google.gwt.view.client.SelectionModel; 
import com.google.gwt.view.client.SingleSelectionModel; 

public class GWTDataGrid implements EntryPoint { 

    private static class Address { 
     private final String houseNumber; 
     private final String streetName; 
     private final String county; 
     private final String postCode; 
     private final String country; 

     public Address(String houseNumber, String streetName, String county, String postCode, String country) { 
       this.houseNumber = houseNumber; 
       this.streetName = streetName; 
       this.county = county; 
       this.postCode = postCode; 
       this.country = country; 
      } 
      } 


    /* 
    * The list of data to display. 
    */ 
    private static final List<Address> ADDRESS = Arrays.asList(
     new Address("a1", "MG Road", "Bangalore", "560068", "India") 
     ,new Address("a2", "AGC Bose Road ", "Kolkata", "700028", "India")); 


    @Override 
    public void onModuleLoad() { 
     DataGrid<Address> table = new DataGrid<Address>(); 

     table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); 

     TextColumn<Address> houseNumber = new TextColumn<Address>() { 

      @Override 
      public String getValue(Address object) { 
       return object.houseNumber; 
      } 
     }; 

     table.addColumn(houseNumber, "House Number"); 


     TextColumn<Address> streetName = new TextColumn<Address>() { 

      @Override 
      public String getValue(Address object) { 
       return object.streetName; 
      } 
     }; 

     table.addColumn(streetName, "Street Name"); 

     TextColumn<Address> county = new TextColumn<Address>() { 

      @Override 
      public String getValue(Address object) { 
       return object.county; 
      } 
     }; 

     table.addColumn(county, "Country"); 

     TextColumn<Address> postCode = new TextColumn<Address>() { 

      @Override 
      public String getValue(Address object) { 
       return object.postCode; 
      } 
     }; 

     table.addColumn(postCode, "Postal Code"); 


     TextColumn<Address> country = new TextColumn<Address>() { 

      @Override 
      public String getValue(Address object) { 
       return object.country; 
      } 
     }; 

     table.addColumn(country, "Country"); 


     // Add a selection model to handle user selection. 
     final SelectionModel<Address> selectionModel = new MultiSelectionModel<Address>(); 
     table.setSelectionModel(selectionModel); 
/*  selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { 
        public void onSelectionChange(SelectionChangeEvent event) { 


`**//WHAT TO DO INSIDE IN IT TO GET ALL THE SELECTED ROW's ITEM**` 

         } 
        } 
       });*/ 



     table.setRowCount(ADDRESS.size(), true); 
     table.setRowData(0, ADDRESS); 
     table.setWidth("100%"); 
     SimpleLayoutPanel slp = new SimpleLayoutPanel(); 
     slp.add(table); 

     // Add it to the root panel. 
     RootLayoutPanel.get().add(slp); 

    } 

} 

선택한 모든 행 인덱스를 저장하는 방법 ?? checkboxcell을 사용하고 있지 않습니다.

답변

1

사용 :

selectionModel.getSelectedSet(); 

documentation를 참조하십시오.

관련 문제