简体   繁体   English

如何在GWT Datagrid中获取所有选定行的值?

[英]How to get all the selected row's value in GWT Datagrid?

I need a way to get all the selected row from my data grid table. 我需要一种从数据网格表中获取所有选定行的方法。 Here is my code: 这是我的代码:

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);

    }

}

How to store all those row index that got selected?? 如何存储所有已选择的行索引? I am not using checkboxcell . 我没有使用checkboxcell

Use: 采用:

selectionModel.getSelectedSet();

See the documentation . 请参阅文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM