1. #1
    Sencha User
    Join Date
    Mar 2013
    Posts
    16
    Vote Rating
    0
    knaier is on a distinguished road

      0  

    Default Render generic matrix in a Data Grid

    Render generic matrix in a Data Grid


    hi,

    If i have a DTO such as the below. I need to render a grid to display the data grid with the column headers being the resultHeaders field.

    Is this possible with GXT 3? i.e. i dont have fields for each column which i think is what GXT expects

    Thanks for your help.

    Code:
    public class ExecResultDTO implements Serializable {
        private static final long serialVersionUID = -3029757106131905189L;
    
    
        private String stratPath;
    
    
        private String requestedBy;
    
    
        private Date responseDt = new Date();
    
    
        private List<String> resultHeaders;
    
    
        private Map<String, List<Object>> data;
    
    
        public String getStratPath() {
            return stratPath;
        }
    
    
        public void setStratPath(String stratPath) {
            this.stratPath = stratPath;
        }
    
    
        public String getRequestedBy() {
            return requestedBy;
        }
    
    
        public void setRequestedBy(String requestedBy) {
            this.requestedBy = requestedBy;
        }
    
    
        public Date getResponseDt() {
            return responseDt;
        }
    
    
        public void setResponseDt(Date responseDt) {
            this.responseDt = responseDt;
        }
    
    
        public List<String> getResultHeaders() {
            return resultHeaders;
        }
    
    
        public void setResultHeaders(List<String> resultHeaders) {
            this.resultHeaders = resultHeaders;
        }
    
    
        public Map<String, List<Object>> getData() {
            return data;
        }
    
    
        public void setData(Map<String, List<Object>> data) {
            this.data = data;
        }
    }

  2. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,717
    Vote Rating
    89
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    Yes. ValueProvider is just an interface, you can build whatever implementation you want, which will just describe how to get (and set!) a property in an object. In your case, assuming each ExecResultDTO is a new row, you'd make a ValueProvider<ExectResultDto, T> for each column that draws some T.

    Here is a blog post that discusses this concept in charts - in a Grid you would just make new column config objects instead of adding new fields: http://www.sencha.com/blog/building-gxt-charts/ Look specifically at the ValueProvider subheading.

  3. #3
    Sencha User
    Join Date
    Mar 2013
    Posts
    16
    Vote Rating
    0
    knaier is on a distinguished road

      0  

    Default


    hi Colin/GXT Community,

    I've got further and it renders the horizontal date series but the value series is not populated.

    Am i doing something stupid? any ideas would be much appreciated!

    Thanks for your help.


    final ListStore<QStratExecResultDataRowDTO> storeChart = new ListStore<QStratExecResultDataRowDTO>(new ModelKeyProvider<QStratExecResultDataRowDTO>() {
    @Override
    public String getKey(QStratExecResultDataRowDTO item) {
    return item.toString();
    }
    });
    storeChart.addAll(dataByRow);


    final Chart<QStratExecResultDataRowDTO> chart = new Chart<QStratExecResultDataRowDTO>();
    chart.setStore(storeChart);
    chart.setShadowChart(true);


    NumericAxis<QStratExecResultDataRowDTO> axis = new NumericAxis<QStratExecResultDataRowDTO>();
    axis.setPosition(Position.LEFT);


    for (int i = 1; i < result.getResultHeaders().size() && i == 1; i++) {
    final int headerCurrent = i;
    final String headerName = result.getResultHeaders().get(i);
    axis.addField(new ValueProvider<QStratExecResultDataRowDTO, Number>() {
    @Override
    public Number getValue(QStratExecResultDataRowDTO object) {
    if (headerCurrent < object.getData().size()) {
    Object val = object.getData().get(headerCurrent);


    try {
    if (val != null) {
    String valStr = val.toString();
    if (valStr.contains(".")) {
    return Double.parseDouble(valStr);
    }
    return Integer.parseInt(valStr);
    }
    } catch (Exception x) {
    return null;
    }
    }


    return null;
    }


    @Override
    public void setValue(QStratExecResultDataRowDTO object, Number value) {


    }


    @Override
    public String getPath() {
    return headerName;
    }
    });
    }


    TextSprite title = new TextSprite("Value");
    title.setFontSize(18);
    axis.setTitleConfig(title);
    axis.setMinorTickSteps(1);
    axis.setDisplayGrid(true);
    PathSprite odd = new PathSprite();
    odd.setOpacity(1);
    odd.setFill(new Color("#ddd"));
    odd.setStroke(new Color("#bbb"));
    odd.setStrokeWidth(0.5);
    axis.setGridOddConfig(odd);
    axis.setMinimum(0);
    axis.setMaximum(100);
    chart.addAxis(axis);


    CategoryAxis<QStratExecResultDataRowDTO, String> catAxis = new CategoryAxis<QStratExecResultDataRowDTO, String>();
    catAxis.setPosition(Position.BOTTOM);
    catAxis.setField(new ValueProvider<QStratExecResultDataRowDTO, String>() {
    @Override
    public String getValue(QStratExecResultDataRowDTO object) {
    return object.getData().get(0) + "";
    }


    @Override
    public void setValue(QStratExecResultDataRowDTO object, String value) {


    }


    @Override
    public String getPath() {
    return result.getResultHeaders().get(0);
    }
    });
    title = new TextSprite(result.getResultHeaders().get(0));
    title.setFontSize(18);
    catAxis.setTitleConfig(title);
    catAxis.setLabelProvider(new LabelProvider<String>() {
    @Override
    public String getLabel(String item) {
    return item;
    }
    });
    chart.addAxis(catAxis);


    final LineSeries<QStratExecResultDataRowDTO> series = new LineSeries<QStratExecResultDataRowDTO>();
    series.setYAxisPosition(Position.LEFT);
    series.setYField(new ValueProvider<QStratExecResultDataRowDTO, Number>() {
    @Override
    public Number getValue(QStratExecResultDataRowDTO object) {
    int headerCurrent = 1;
    if (headerCurrent < object.getData().size()) {
    Object val = object.getData().get(headerCurrent);


    try {
    if (val != null) {
    String valStr = val.toString();
    if (valStr.contains(".")) {
    return Double.parseDouble(valStr);
    }
    return Integer.parseInt(valStr);
    }
    } catch (Exception x) {
    return null;
    }
    }


    return null;
    }


    @Override
    public void setValue(QStratExecResultDataRowDTO object, Number value) {
    // TODO Auto-generated method stub


    }


    @Override
    public String getPath() {
    return "Field1";
    }
    });


    final Legend<QStratExecResultDataRowDTO> legend = new Legend<QStratExecResultDataRowDTO>();
    legend.setPosition(Position.RIGHT);
    legend.setItemHighlighting(true);
    legend.setItemHiding(true);
    chart.setLegend(legend);


    series.setStroke(new RGB(194, 0, 36));
    series.setShowMarkers(true);
    Sprite marker = Primitives.square(0, 0, 6);
    marker.setFill(new RGB(194, 0, 36));
    series.setMarkerConfig(marker);
    series.setHighlighting(true);
    chart.addSeries(series);
    chart.setWidth("100%");
    chart.setHeight(200);


    chart.redrawChart();

  4. #4
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,717
    Vote Rating
    89
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    You seem to have forgotten to add the QStratExecResultDataRowDTO class, as well as the data that is in 'result'. Can you post a runnable example, preferably implementing EntryPoint so that we can actually run the sample?

Thread Participants: 1