I use Kendo grid MVC and In The First Column I Use This Code:
columns.Template(s => s.IsActive).Title("").ClientTemplate(
" <input type='checkbox' \\#= IsActive ? checked='checked' : '' \\# /input>"
).Width(50);
and it works correctly, but when i wanted to use this code in span it's not working i wanted to show text insted of boolean my wrong code is :
columns.Template(s => s.IsActive).Title(T("My Title").ToString()).ClientTemplate(
" <span> \\#= IsActive?" + T("Required") + " : " + T("Optional") + " \\#</span>"
).Width(150);
so what's wrong with second one?
From looking at it the code is not being picked up because it it a mix of html and javascript. In the client templating then this should would in Kendo:
#if(data.IsActive === true){#<span>Required</span>#}else{#<span>Optional</span>#}#
I find this messy so I personally like to pull this out of the template and use a function as it means I can edit it easier and don't get frustrated. so something like this:
.ClientTemplate("#=TextFormatter(data.IsActive)#")
Then in the javascript would be
function TextFormatter(value)
{
var returnString = '';
if(value === true)
{
returnString = '<span>Required</span>';
}
else
{
returnString = '<span>Optional</span>';
}
return returnString;
}
For further reading check this link out: How do I have conditional logic in a column client template
Related
I am using kendo grid + mvc 5. in that,
columns.Template(e => { }).ClientTemplate..
I just want to use "Contains".
if "SitePlanMediaUrl.Contains(\"" + ViewBag.option + "\"))" value then ClientTemplate item show, otherwise not.
note - I have a value in "ViewBag.option"
-code line -
columns.Template(e => { }).ClientTemplate("<a href='" + Url.Action("download", "common", new { area = "" }) + "?url=#=SitePlanMediaUrl#&fileName=#=MediaTitle#' title='Download Media' class='icon download' target='_blank'></a> #if(SitePlanMediaUrl.Contains(\"" + ViewBag.option + "\")) {# <a href='javascript:void(0)' class='icon upload' onclick='SitePlanUploadMedia(#=SitePlanMediaId#,\"#=MediaTitle#\", \"#=MediaTitle#\")' title='Upload Media'></a> #}# <a href='javascript: void(0)' class='icon delete' onclick='deleteRowConfirm(\"sitePlanMediagrid\",this)' title='Delete Media'></a>").Title("Action").Width(50);
if I get in between SitePlanMediaUrl then tag will show.
thanks.
I suspect this is not translated to C#, but to javascript, due to this being a ClientTemplate in the kendo framework.
Could you try with if(SitePlanMediaUrl.indexOf(\"" + ViewBag.option + "\") > -1)
.
The indexOf() method returns the index within the calling String
object of the first occurrence of the specified value starting the search at fromIndex. Returns -1 if the value is not found.
I'm using the Password HTML Helper in MVC5 to hide the social security number as it is entered.
#Html.Password("s", null, new { #maxlength = 9, autocomplete = "off" })
The problem I see with it is you just see dots as you type. Is there any way the helper behavior can be modified to show the characters you are typing in for a second or two then have them transformed to dots? That behavior would let the user confirm they are typing in the correct character. If the helper behavior cannot be modified is there another way to accomplish this?
I found this fiddle maybe you can use this as an option
http://jsfiddle.net/Ngtp7/
$(function(){
$(".showpassword").each(function(index,input) {
var $input = $(input);
$('<label class="showpasswordlabel"/>').append(
$("<input type='checkbox' class='showpasswordcheckbox' />").click(function() {
var change = $(this).is(":checked") ? "text" : "password";
var rep = $("<input type='" + change + "' />")
.attr("id", $input.attr("id"))
.attr("name", $input.attr("name"))
.attr('class', $input.attr('class'))
.val($input.val())
.insertBefore($input);
$input.remove();
$input = rep;
})
).append($("<span/>").text("Show password")).insertAfter($input);
});
});
Is there a more efficient way for displaying a tool tip once a cell is hovered? Using the structure attribute to format the datagrid, is there a way to use formatter to display a dijit toolTip rather than using the html title attribute.
Here is the column in which the toolTip is displaying.
var subscriberGridLayout = [
{
name: " ",
field: "ExpirationDate",
formatter: function(value){
if(value){
expDate = formatDateIE(value);
return toolTip();
}
else
return " ";
},
styles: "text-align: center;",
width: "30px"
},
Here is the function that displays a tooltip icon through the image tag but instead of a dijit toolTip it simply uses html's title to display a popup.
function toolTip(){
src = "'/Subscriber/resources/images/icons/icon_error.gif'/>";
if(dojo.date.difference(today, expDate) <= 0 ){
message = "Credential expired.";
return "<img title='"+ message + "' src=" + src + "";
} else if(dojo.date.difference(today, expDate) <= 60) {
message = "This Subscriber will expire in " + dojo.date.difference(today, expDate) + " days."
+ "
To prevent an interruption in the Subscriber’s access, please sumbit a request to " +
"renew the Subscriber within 30 days of the expiration date.";
return "<img title='"+ message + "' src=" + src + "";
} else {
return " ";
}
}
I would do something like:
new Tooltip({
connectId: grid.domNode,
selector: "td",
getContent: function(matchedNode){
return matchedNode.innerText
}
});
With grid.domNode you can get the generated DOM of your widget. A grid generates a table-structure, so you can get the cells by using the selector and getContent properties.
I must say it's not really the correct way to do it because now you're playing with the internal structure of the Dojo widget. If they once decide not to use a table as DOM structure your code won't work.
But I don't think there is a better way to achieve this, in the end you will always have to translate the Dojo cell to a DOM node (because tooltips are DOM based). You can of course connect a tooltip to each cell, but I tried that before and it was a little buggy (sometimes the tooltip didn't pop up).
I also made a JSFiddle to show you a working example.
I have a view that accepts 2 string parameters and 2 date values. User hits search button and they get filtered output to the screen. This all works perfectly well until a user inputs a string with a space. i.e. they can search for 'waste' but not 'waste oil'.
Interestingly, in the latter, the parameter is ok from Javascript before the call is made. But on entering the controller code it goes form being 'waste oil' on client to 'waste'. When this happens the other parameters get set to NULL crashing the system.
I've tried replacing the spaces if present with '#' character then stripping out and putting back in ' ' on the controller side. This is a messy fudge and only appears to work with one parameter.
There must be a simple explanation for this parameter data loss, any comments much appreciated
Not sure a code example is needed but here it is anyway if it help:
My controller header :
public ActionResult IndexSearch(int? page, string searchText,string searchTextSite,string StartDate,string EndDate)
{
My HTML Javascript :
function Search(sSearchText,sSite) {
sSearchText = sSearchText.toString().replace(" ", "#");
sSite = sSite.toString().replace(" ", "#");
debugger;
alert($("#AbsolutePath").val() + "Waste.mvc/IndexSearch?searchText=" + sSearchText + "&searchTextSite=" + sSite + "&StartDate=" + $('#StartDate').val() + "&EndDate=" + $('#EndDate').val());
$("#ResultsList").load($("#AbsolutePath").val() + "Waste.mvc/IndexSearch?searchText=" + sSearchText + "&searchTextSite=" + sSite + "&StartDate=" + $('#StartDate').val() + "&EndDate=" + $('#EndDate').val(),
function() {
$('#LoadingGif').empty();
});
$('#LoadingGif').empty().html('<img src="' + $("#AbsolutePath").val() + 'Content/images/ajax-loader.gif" alt="Loading image" />');
}
You are not URL encoding your parameters when sending the AJAX request because you are using string concatenations when building the url. You could use the following technique in order to have properly encoded values:
var url = $('#AbsolutePath').val() + 'Waste.mvc/IndexSearch';
var data = {
searchText: sSearchText,
searchTextSite: sSite ,
StartDate: $('#StartDate').val(),
EndDate: $('#EndDate').val()
};
$('#ResultsList').load(url, data, function() {
$('#LoadingGif').empty();
});
Now you will get correct values on the server.
I want to make the following :
1. I have the following formatter function:
function ActionDescriptionFormatter(cellval, opts, rwdat, _act) {
var str = "<a border='0' style='text-decoration: none;' href='/Admin/IdeaDescription?id=" + cellval + "' title='Description'><img src='/images/aico_descr.png' alt='Description' border='0' /></a>";
return str;
}
I want to add also current pagenumber to url.
I want to set page of grid if It's passed via url
How to do it?