I have a GXT grid where I am applying html tag to highlight the text "def" in the word "defining". But instead of taking as HTML tag, it considers the as a string and displays output as <mark>def</mark>ining
. Can you please help me how to resolve this ?
private static String doHighlight(String dtoData){ //dtoData is "defining"
int dtoLength = dtoData.length();
int i = -1;
String newDtoData = null;
String finalDtoData = null;
String highlightStartTag = "<mark>";
String highlightEndTag = "</mark>";
if (dtoData != null && dtoData != "") {
i = dtoData.toLowerCase().indexOf("def", i+1);
if(i<0){
finalDtoData = dtoData;
}else{
newDtoData = highlightStartTag +dtoData.substring(0, i) + dtoData.substring(i, "def".length()) + highlightEndTag;
finalDtoData = newDtoData + dtoData.substring("def".length(), dtoLength);
i = -1;
}
}
return finalDtoData;
}
private static Map<Integer, String> findMatches(String searchText, String dtoValue, int rowCount) {
Map<Integer,String> matchesMap = new HashMap<Integer,String>();
if (dtoValue != null && dtoValue != "") {
i = dtoValue.toLowerCase().indexOf(searchText, i+1);
if(i>=0){
newDtoData = dtoValue.replaceAll(searchText, "<span style='background-color: yellow; !important'>"+searchText+"</span>");
matchesMap.put(rowCount, newDtoData);
i = -1;
}
}
return matchesMap;
Pass the above matchesMap to the below loop and iterate it over the rowcount. You can get the cell using column and row count. After getting the cell element, you can set the innerHTML.
for(int rowId:matchesMap.keySet()){
if(!matchesMap.get(rowId).isEmpty()){
Element cellElement = viewComponent.getView().getCell(rowId, columnId);
if(cellElement != null){
cellElement.setInnerHTML(matchesMap.get(rowId));
}
}
}