简体   繁体   中英

GWT CELLTABLE : How to add column in celltable which is combination of non-editable text + hyperlink

I want to add link in my celltable's column ie"validationStatus" some values are "valid" as well as "invalid" when value is invalid then I want to make invalid as link (How to ?) & when value is valid then I want to make it as text

How to add link in celltables particular column ?

I want to add Column which is combination of non-editable text(valid) + hyperlink (invalid)if any.

Presumably you have some sort of list of these values associated in some fashion with each row of your table. Extend the Column class and set it to display a TextCell. Override the render method in your Column class so that when it renders these values, it checks them for validity, and either appends the SafeHtml for an anchor (invalid values that are links), or it appends plain escaped text (valid values that are not links). Add this Column subclass to your table.

Sample code: It works :)

    public class CustomColumn extends  Column<Record, String>{

    public CustomColumn(Cell<String> cell) {
        super(cell);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void render(Cell.Context context, Record object, com.google.gwt.safehtml.shared.SafeHtmlBuilder sb) {

        super.render(context, object, sb);

        String validationStatus= object.getValidationStatus();
        if(validationStatus.equals("Invalid") ){
             sb.appendHtmlConstant("<a href='http://www.google.com'> Invalid </a>");
        }else if(validationStatus.equals("Valid")){
            sb.appendEscaped("Valid");
        }
    }


    @Override
    public String getValue(Car object) {
        // TODO Auto-generated method stub
        return null;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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