10

I am trying to use the new Kendo UI grid from asp.net mvc 3.

I am having a table the table is generated automatically from a controller in asp.net mvc 3.

And display it with Kendo.ui grid.

However, I am having the html code inside of the cells instead of the html controls

Example:

it display in the cell: <input checked="checked" class="check-box" disabled="disabled" type="checkb.. instead of an input, the code in the View is @html.input

or <a href="/Admin/Edit">Edit</a> | <a href="/Admin/Details">Details</a> | <a href="/Adm instead of a link ( code in the View is @Html.actionLink)

How can I make it encode html code ?

This is my script:

$(document).ready(function() {
    $("#calendrierMatch").kendoGrid({

    });
});

Thanks

2
  • Can you post the Javascript code where you create the kendoUI grid? Commented Jul 4, 2012 at 10:08
  • this is my script: $(document).ready(function() { $("#calendrierMatch").kendoGrid({ }); }); Commented Jul 4, 2012 at 11:46

3 Answers 3

27

The KendoUI Grid automatically encodes the content of the grid, that's why you get the text <input type= ... instead of the actual input controll.

You can disable the encoding for a given column with using the encoded options (see documentation):

encoded: Boolean(default: true) Specified whether the column content is escaped. Disable encoding if the data contains HTML markup.

So you need something like:

 $(document).ready(function(){
      $("#grid").kendoGrid({
      //...
        columns: [
           {
               field: "Column containing HTML",
               encoded: false
           }
        ]          
      });
 });
Sign up to request clarification or add additional context in comments.

7 Comments

Hi nemesv, thanks for your advice, I am using $("#grid").kendoGrid() to create my grid, the columns and datas are get directly from the table on the view ( with <thead> and <tbody> ), in order to use the encoded: false option, that means that for each time I need to declare all the columns for the table in the kendoGrid call ?
Based on the documentation in the current version there is no other way to turn the encoding off globally. So I'm afraid you need to specify all the columns, and turn off encoding individually...
I tried out the latest beta version, and I can get now the html rendered, however, cannot sort out the columns, even with the sortable: true option, I can see the icons up/down, but when clicking results nothing, have you seen anything similar ?
I haven't tried the beta yet, and I don't know why is the sorting not working, but I think this is then a different question.
Thanks anyway nemesv for your previous advice, it will help me out at one stage or another
|
1

in model binding kendo grid Razor Html Page use this code

@Html.Kendo().Grid(Model).Name("GridName").Columns(col =>{
col.Bound(m => m.ID);
col.Bound(m => m.Name);
col.Template(@<text>
        @Html.Raw(HttpUtility.HtmlDecode( item.Text))
    </text>);
})

Comments

0

You need to add the template feature of kendo grid.

In the below code i have created a text box inside the cell of kendo grid.

 {
     field: "Total",
     title: "Total",
     width: "40px",
     template: "<input type='text'  class=\"quantity_total\"   id='txtTotal_${ItemId}'    
                name='txtTotal_${ItemId}' maxlength='8'    onkeypress = 'return 
                fnCheckNumeric_total(event,this.id)'  />"  
               
},

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.