Search in sources :

Example 1 with DataGrid

use of cn.cerc.jpage.grid.DataGrid in project summer-mis by cn-cerc.

the class ColumnEditor method format.

public String format(Record ds) {
    String data = ds.getString(owner.getField());
    if (owner.getBuildText() != null) {
        HtmlWriter html = new HtmlWriter();
        owner.getBuildText().outputText(ds, html);
        data = html.toString();
    } else if (ds.getField(owner.getField()) instanceof Double) {
        DecimalFormat df = new DecimalFormat("0.####");
        data = df.format(ds.getDouble(owner.getField()));
    }
    if (!this.init) {
        dataSet = gridLine.getDataSet();
        columns = new ArrayList<>();
        for (IField field : gridLine.getFields()) {
            if (field instanceof IColumn) {
                if (((AbstractField) field).isReadonly())
                    continue;
                if (field.getWidth() == 0)
                    continue;
                columns.add(field);
            }
        }
        if (gridLine.getOwner() instanceof DataGrid) {
            DataGrid grid = (DataGrid) gridLine.getOwner();
            if (columns.size() > 0 && grid.getPrimaryKey() == null)
                throw new RuntimeException("BaseGrid.primaryKey is null");
        }
        this.init = true;
    }
    HtmlWriter html = new HtmlWriter();
    String inputStyle = "";
    html.print("<input");
    if (gridLine instanceof MasterGridLine)
        html.print(" id='%s'", this.getDataId());
    else {
        if (owner.getId() != null)
            html.print(" id='%s'", owner.getId());
        inputStyle = "width:80%;";
    }
    inputStyle += "border: 1px solid #dcdcdc;";
    html.print(" type='text'");
    html.print(" name='%s'", owner.getField());
    html.print(" value='%s'", data);
    html.print(" autocomplete='off'");
    html.print(" data-%s='[%s]'", owner.getField(), data);
    if (gridLine instanceof MasterGridLine) {
        html.print(" data-focus='[%s]'", this.getDataFocus());
        if (owner.getAlign() != null)
            inputStyle += String.format("text-align:%s;", owner.getAlign());
        if (owner.getOnclick() != null) {
            html.print(" onclick=\"%s\"", owner.getOnclick());
        } else
            html.print(" onclick='this.select()'");
    }
    if (!"".equals(inputStyle))
        html.print(" style='%s'", inputStyle);
    html.print(" onkeydown='return tableDirection(event,this)'");
    if (dataField.size() > 0) {
        for (String field : dataField) {
            html.print(" data-%s='%s'", field, ds.getString(field));
        }
    }
    if (onUpdate != null)
        html.print(" oninput=\"tableOnChanged(this,'%s')\"", onUpdate);
    else
        html.print(" oninput='tableOnChanged(this)'");
    html.println("/>");
    return html.toString();
}
Also used : AbstractField(cn.cerc.jpage.fields.AbstractField) MasterGridLine(cn.cerc.jpage.grid.lines.MasterGridLine) IColumn(cn.cerc.jpage.core.IColumn) HtmlWriter(cn.cerc.jpage.core.HtmlWriter) DecimalFormat(java.text.DecimalFormat) DataGrid(cn.cerc.jpage.grid.DataGrid) IField(cn.cerc.jpage.core.IField)

Aggregations

HtmlWriter (cn.cerc.jpage.core.HtmlWriter)1 IColumn (cn.cerc.jpage.core.IColumn)1 IField (cn.cerc.jpage.core.IField)1 AbstractField (cn.cerc.jpage.fields.AbstractField)1 DataGrid (cn.cerc.jpage.grid.DataGrid)1 MasterGridLine (cn.cerc.jpage.grid.lines.MasterGridLine)1 DecimalFormat (java.text.DecimalFormat)1