Life is a Short Span, try to earn knowledge in every Field.
Tuesday, 11 March 2014
Tuesday, 18 February 2014
How to open a new tab On click of a hyper-linked column in Telerik Razor Grid
Today i got a requirement to open a external URL in a tab when the linked column is clicked.
This can be achieved by simply adding the client template/ template to the linked column.
1) Using Template Attribute in the Telerik Grid
2) Using Client Template Attribute in the Telerik Grid
Output:
But the really annoying is that when you click the link it is throwing error as
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable"
This is because the IIS is unable to resolve the path.
Solution to the above issue:
The above issue can be fixed by a simple trick, just you need to append the http:// to the website in the client template or in the template attribute. See the code below:
This can be achieved by simply adding the client template/ template to the linked column.
1) Using Template Attribute in the Telerik Grid
column.Bound(a => a.Website) .Template(@<text><a href="@Url.Content(item.Website)" target="_blank">@item.Website</a></text>) .HeaderTemplate( @<text> <a href="javascript:void(0)" class="t-link" orderby="Website">Website</a> @Html.TextBoxFor(m => m.Filter.Website) </text>);
2) Using Client Template Attribute in the Telerik Grid
column.Bound(a => a.Website) .ClientTemplate("<a href='<#= Website #>' target='_blank'><#= Website #></a>") .HeaderTemplate( @<text> <a href="javascript:void(0)" class="t-link" orderby="Website">Website</a> @Html.TextBoxFor(m => m.Filter.Website) </text>);
Output:
But the really annoying is that when you click the link it is throwing error as
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable"
This is because the IIS is unable to resolve the path.
Solution to the above issue:
The above issue can be fixed by a simple trick, just you need to append the http:// to the website in the client template or in the template attribute. See the code below:
column.Bound(a => a.Website) .Template(@<text><a href="@Url.Content("http://"+item.Website)" target="_blank">@item.Website</a></text>) .HeaderTemplate( @<text> <a href="javascript:void(0)" class="t-link" orderby="Website">Website</a> @Html.TextBoxFor(m => m.Filter.Website) </text>);
Note: Similarly if it is a mail ID column then, use mailto: as the prefix.
Thats it, Enjoy!
Sunday, 12 January 2014
How to Add Re-ordering of the columns in Telerik MVC or Razor Grid.
Some times it is required that the column had to be re-ordered in a grid as, we are using a Telerik grid , as adding the property reorder will do the task.
Here is the code below to do it:
Here is the code below to do it:
.Reorderable(reorder => reorder.Columns(true))
Just add this line to your Telerik Razor grid, it will do the task.
Happy Coding!
How to show the Pager in Telerik Grid both in top and bottom.
While working in a project , my client wants to show the paging in the grid in both in the top of the grid as well as in the bottom of the grid also. As I am using the Telerik grid, it has a property to set while creating the grid.
So here is the code for it:
So here is the code for it:
Happy Coding!.Pageable(p => { p.Style(GridPagerStyles.NextPreviousAndNumeric | GridPagerStyles.PageSizeDropDown);
p.Position(GridPagerPosition.Both); // this line will do the Magic p.PageSize(int.Parse(ViewBag.PageSize ?? "50"), new[] { 10, 20, 50 }); }).Sortable()
Subscribe to:
Posts (Atom)