2

Can I directly bind a pre formatted value to a kendo grid column? The data contains html tags and I want the column to render the data with formatting and not treat the tags as text. I could use ng-template to achieve the desire output but for that I will need to parse the whole data, store it into different keys and use them to format in the .html file. Is there anyway I could make kendo render the html inside the column?

1 Answer 1

7

You can render the HTML using a wrapper element within the cell template, and bind its innerHtml property to the data item field, containing the HTML you would like to render, e.g.:

<kendo-grid-column field="htmlField">
              <ng-template kendoGridCellTemplate let-dataItem>
                <div [innerHtml]="dataItem.htmlField"></div>
              </ng-template>
            </kendo-grid-column>

Model:

{
        "ProductID": 1,
        "ProductName": "Chai",
        "SupplierID": 1,
        "CategoryID": 1,
        "QuantityPerUnit": "10 boxes x 20 bags",
        "UnitPrice": 18,
        "UnitsInStock": 39,
        "UnitsOnOrder": 0,
        "ReorderLevel": 10,
        "Discontinued": false,
        "Category": {
            "CategoryID": 1,
            "CategoryName": "Beverages",
            "Description": "Soft drinks, coffees, teas, beers, and ales"
        },
        "FirstOrderedOn": new Date(1996, 8, 20),
        "htmlField": "<h1>RENDERED HTML</h1>"
    },

EXAMPLE

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.