Search code examples
gwtgridgwt2gxt

How to put GXT Grid values to Map


I want to save the grid header and col data in HashMap.

Map<String,List<String>> gridData = new HashMap<String,List<String>>(); // key ->header , value -> list of col



    ColumnModel<RiaBean> columnModel = grid.getColumnModel();
    for (int colonne = 0; colonne < columnModel.getColumnCount(); colonne++) {
        String header= columnModel.getColumnHeader(colonne).toString();

    /* missing code 
        **i have header name how to get the list of values of that header**
    */

    gridData.put(header,list<>)

i missing code part i want get list of all values of same header

Please help.


Solution

  • First you have to assign id to all column as follow

    ColumnConfig xyz = new ColumnConfig();
    xyz.setId("xyz");
    xyz.setHeader("xyz");
    
    ColumnConfig abc = new ColumnConfig();
    abc.setId("abc");
    abc.setHeader("abc");
    

    than after you have to fetch all record from grid using following code

    Map<String,List<String>> gridData = new HashMap<String,List<String>>(); 
    
    List<String> xyzList = new ArrayList();
    List<String> abcList = new ArrayList();
    
    for (ColumnConfig column : grid.getColumnModel().getColumns()) {
       for (DatastoreConfig datastoreConfig : grid.getStore().getModels()) {
             if(column.getId().equals("xyz")){
                   xyzList.add(datastoreConfig.get(column.getId()).toString());
             }
    
             if(column.getId().equals("abc")){
                   abcList.add(datastoreConfig.get(column.getId()).toString());
             }
         }
     }
    
    gridData.put("xyz",xyzList);
    gridData.put("abc",abcList);
    

    hope it will help you.