Category / Section
How to remove the junk data, when the string column content contains angular bracket in JSON mode ?
1 min read
Problem
String column in the Grid displays junk data (_tmplitem) when the content contains angle brackets (<,>, etc.) in it.
Solution
While using jquery templates (jquery.tmpl.js) to render the template in JSON mode Grid, the junkdata (_tmplitem) is added with the angle brackets in the grid data. To resolve this problem in the string columns, replace the columns inner html value with the data of column at runtime by using the QueryCellInfo client side event.
CSHTML
@(Html.Syncfusion().Grid<Student>("GenericListGrid") .ActionMode(ActionMode.JSON) .EnableSorting() .EnablePaging() .Column(cols => { cols.Add(c => c. Title).HeaderText("Title");//Column contains the junk data }) .ClientSideEvents(event=>event.QueryCellInfo("QueryCellHandler"))//triggering the QueryCellInfo handler )
JavaScript
<script type="text/javascript"> function QueryCellHandler(sender, args) { if ($(args.Element).hasClass("RowCell") && (args.Element.innerHTML.indexOf("_tmplitem") != -1)) args.Element.innerHTML = args.Data.Title; //replacing the innerhtml of column } </script>